Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content workflow #310

Merged
merged 112 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
ec875f8
Interim
benmerckx Mar 3, 2023
fbe1bb2
Interim
benmerckx Mar 3, 2023
e78e34d
Interim
benmerckx Mar 6, 2023
40c3424
Interim
benmerckx Mar 8, 2023
bd9dc2d
Interim
benmerckx Mar 8, 2023
be6cc1f
Interim
benmerckx Mar 13, 2023
76df9cd
Interim
benmerckx Mar 14, 2023
b9dd404
Interim
benmerckx Mar 15, 2023
8a4f3ad
Interim
benmerckx Apr 4, 2023
235b80a
Interim
benmerckx Apr 11, 2023
bacd55b
Interim
benmerckx Apr 12, 2023
5337bd7
Sketch out the Resolver
benmerckx Apr 20, 2023
81822bf
Parse rich text linked entries
benmerckx Apr 20, 2023
c45db5a
Interim
benmerckx Apr 20, 2023
fbe846b
Interim
benmerckx Apr 27, 2023
5c14e9e
Interim
benmerckx May 1, 2023
e7409e6
Interim
benmerckx May 2, 2023
7a81a0a
Interim - sections
benmerckx May 3, 2023
d80b751
Update type & schema api
benmerckx May 4, 2023
db9eda5
Interim
benmerckx May 4, 2023
6c7682c
Interim
benmerckx May 5, 2023
61009c0
Interim
benmerckx May 5, 2023
f894e9f
Hub => Connection
benmerckx May 8, 2023
f03e8b8
Remove the generic type param from connection
benmerckx May 8, 2023
9dee771
Interim
benmerckx May 8, 2023
f05b390
Interim
benmerckx May 8, 2023
939647f
Interim
benmerckx May 9, 2023
1e2a59e
Move things around
benmerckx May 9, 2023
15b270d
Interim
benmerckx May 9, 2023
7618884
Generate & serve cli
benmerckx May 9, 2023
8cbdee2
Interim
benmerckx May 9, 2023
28e7f7e
Move state to atoms
benmerckx May 10, 2023
416fa62
Minor
benmerckx May 9, 2023
dc03f73
Interim
benmerckx May 11, 2023
f7facb8
Interim
benmerckx May 12, 2023
f40fb11
Interim
benmerckx May 12, 2023
781c4bf
Interim
benmerckx May 12, 2023
5104889
Interim
benmerckx May 15, 2023
57e7374
Interim
benmerckx May 16, 2023
c8e632b
Add skip/take
benmerckx May 16, 2023
0760252
Interim
benmerckx May 17, 2023
e9f2fd3
Interim
benmerckx May 22, 2023
40caeb4
Shape backend to accept saving and publishing drafts
benmerckx May 23, 2023
79a7ecb
Interim
benmerckx May 24, 2023
6078607
Setup preview handler
benmerckx May 25, 2023
c39ab54
Pass preview token
benmerckx May 26, 2023
8955970
Encode preview data - not functional yet
benmerckx May 26, 2023
481a8e7
Interim
benmerckx May 30, 2023
a3557bf
Interim
benmerckx May 30, 2023
a2ab84f
Interim
benmerckx May 30, 2023
806a348
Interim
benmerckx May 31, 2023
c9daf42
Interim - I think keeping a record of links is probably the way to go…
benmerckx May 31, 2023
ab962a3
Interim - tweak root to accept a tree of entries to seed
benmerckx Jun 1, 2023
dad4587
Interim
benmerckx Jun 2, 2023
2879ed2
Onyl warn for published entries missing a seed source
benmerckx Jun 2, 2023
32d1af3
Finally we have a failing test
benmerckx Jun 2, 2023
b382ff9
Add DeepMap util
benmerckx Jun 5, 2023
c80a2fc
Add LinkResolver to query linked fields in a second pass
benmerckx Jun 5, 2023
985ab0e
Check in deps
benmerckx Jun 5, 2023
e63cc7f
Start moving link field to new apis
benmerckx Jun 5, 2023
e9cab45
Update link field
benmerckx Jun 6, 2023
229df64
Interim
benmerckx Jun 7, 2023
b14e0c6
Interim
benmerckx Jun 8, 2023
7173a2a
Update yarn
benmerckx Jun 8, 2023
eeaee0d
Fix client import
benmerckx Jun 8, 2023
d0f7aba
Fix entry data inferred expression
benmerckx Jun 8, 2023
e03067b
Start working through all the type changes
benmerckx Jun 8, 2023
c71063f
Update data fetching in dashboard
benmerckx Jun 8, 2023
27b9b54
Cleanup debug traces
benmerckx Jun 8, 2023
b3b8b0b
Activate the explorer views
benmerckx Jun 9, 2023
8280083
Interim
benmerckx Jun 9, 2023
c2e3744
Update more internals
benmerckx Jun 12, 2023
c149661
Interim
benmerckx Jun 12, 2023
47a7fd4
Fix a few types, I think these should be restructured later
benmerckx Jun 13, 2023
6fd6875
Interim
benmerckx Jun 13, 2023
acb7bca
Start updating the cloud backend
benmerckx Jun 13, 2023
12b9d55
@alinea/content => @alinea/generated
benmerckx Jun 13, 2023
7d3b397
Store db in a js file like we did before
benmerckx Jun 13, 2023
a89a251
Fix dashboard generation
benmerckx Jun 14, 2023
26fb1d1
Remove archive
benmerckx Jun 14, 2023
19530bb
Remove cloud exports
benmerckx Jun 14, 2023
2a12f88
Setup cloud auth view
benmerckx Jun 14, 2023
b61be27
Remove auth during dev
benmerckx Jun 14, 2023
207ecea
Remove debug data, to be replaced with a preview widget
benmerckx Jun 14, 2023
71c64f0
Note
benmerckx Jun 14, 2023
a95d9e5
Check node version in cli, remove experimental-specifier-resolution boot
benmerckx Jun 14, 2023
d813941
Remove debug traces
benmerckx Jun 14, 2023
d902061
Finish rebase
benmerckx Jun 14, 2023
24bbb39
Run test suite
benmerckx Jun 14, 2023
2cbceb3
Update ci node version
benmerckx Jun 14, 2023
0497708
Make things compile in Next.js
benmerckx Jun 14, 2023
99a3bab
Enable uploads
benmerckx Jun 15, 2023
484f105
Fix upload location in dev mode
benmerckx Jun 15, 2023
8dd9ef6
Interim
benmerckx Jun 15, 2023
f77e697
Errors either have a code or they don't
benmerckx Jun 15, 2023
aa83058
Minor
benmerckx Jun 15, 2023
85433b4
Oops
benmerckx Jun 15, 2023
f0bdb85
Compress preview cookie payload
benmerckx Jun 15, 2023
746aefb
Minor
benmerckx Jun 15, 2023
dc06a51
Remove summary link
benmerckx Jun 15, 2023
81e0eb8
Setup new entry modal
benmerckx Jun 15, 2023
b5a630f
Improve symlink creation
benmerckx Jun 16, 2023
04d511e
Resolve link fields
benmerckx Jun 16, 2023
b1092c9
Edit website
benmerckx Jun 16, 2023
a2c539c
Setup doc page
benmerckx Jun 16, 2023
e147688
Level was incorrect which is why parent entries would not sort properly
benmerckx Jun 16, 2023
31aba62
Add build script
benmerckx Jun 19, 2023
decd66b
Interim
benmerckx Jun 19, 2023
44aaca6
WIP
benmerckx Jun 19, 2023
88a82eb
Update dev command
benmerckx Jun 20, 2023
b0dafa2
Cleanup
benmerckx Jun 20, 2023
9abab3a
Check in deps
benmerckx Jun 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .alinea/.keep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Contents of this folder are autogenerated by alinea
192 changes: 2 additions & 190 deletions .esbx.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import {ReporterPlugin} from '@esbx/reporter'
import {list, report} from '@esbx/util'
import {spawn} from 'child_process'
import type {BuildOptions} from 'esbuild'
import esbuild from 'esbuild'
import {report} from '@esbx/util'
import {getManifest} from '@esbx/workspaces'
import fs from 'fs-extra'
import glob from 'glob'
import {bundleTsPlugin} from './src/dev/bundle-ts.js'
import {cssPlugin} from './src/dev/css.js'
import {internalPlugin} from './src/dev/internal.js'
import {resolvePlugin} from './src/dev/resolve'
import {sassPlugin} from './src/dev/sass.js'

export const VersionTask = {
command: 'version <semver>',
Expand All @@ -20,182 +11,3 @@ export const VersionTask = {
report(`bumped version to ${semver}`, false)
}
}

import {reportTime} from '@esbx/util'
import {execSync} from 'child_process'
import which from 'which'

function createTypes() {
const tsc = which.sync('tsc') as string
return reportTime(
async () => {
execSync(tsc, {stdio: 'inherit', cwd: process.cwd()})
},
'type checking',
err => {
if (err) return `type errors found`
return `types built`
}
)
}

function release({
command,
watch,
config
}: {
command: string
watch: boolean
config: Partial<BuildOptions>
}) {
return {
command,
description: 'Build workspaces',
options: [['-w, --watch', 'Rebuild on source file changes']],
async action(options) {
if (!fs.existsSync('./dist/index.d.ts')) await createTypes()
const cwd = process.cwd()
const entryPoints = glob
.sync('src/**/*.{ts,tsx,js,woff2}', {cwd})
.filter(entry => {
if (entry.includes('/static/')) return false
if (entry.endsWith('.test.ts') || entry.endsWith('.test.tsx'))
return false
if (entry.endsWith('.stories.tsx')) return false
return true
})
const staticFolders = glob.sync('src/**/static', {cwd})
for (const folder of staticFolders) {
const target = folder.replace('src/', 'dist/')
fs.copySync(folder, target)
}
const buildOptions: BuildOptions = {
jsx: 'automatic',
format: 'esm',
loader: {
'.woff2': 'copy',
'.d.ts': 'copy'
},
...config,
platform: 'neutral',
outdir: 'dist',
bundle: true,
// sourcemap: true,
absWorkingDir: cwd,
entryPoints: entryPoints,
mainFields: ['module', 'main'],
plugins: list(
sassPlugin,
cssPlugin,
internalPlugin,
resolvePlugin,
options.silent
? undefined
: ReporterPlugin.configure({name: 'alinea'}),
bundleTsPlugin,
config.plugins
)
}
if (watch || options.watch)
return esbuild.context(buildOptions).then(ctx => ctx.watch())
return esbuild.build(buildOptions)
}
}
}
export const BuildTask = release({command: 'build', watch: false, config: {}})
let devProcess
export const DevTask = release({
command: 'dev',
watch: true,
config: {
plugins: [
{
name: 'start',
setup(build) {
build.onEnd(() => {
if (devProcess) return
devProcess = spawn('node ./dist/dev/serve.js', {
stdio: 'inherit',
shell: true
})
})
}
}
]
}
})

export const clean = {
action() {
fs.removeSync('dist')
fs.removeSync('apps/web/.alinea')
fs.removeSync('apps/demo/.alinea')
}
}

import {findNodeModules} from '@esbx/util'
import {getManifest} from '@esbx/workspaces'
import crypto from 'crypto'
import path from 'path'

export type TestTaskConfig = {
globPattern?: string
buildOptions?: BuildOptions
}

export const TestTask = {
command: 'test [pattern]',
describe: 'Test workspaces',
async action(pattern?: string) {
const cwd = process.cwd()
const filter = (pattern || 'Test').toLowerCase()
const files = glob.sync('src/**/*.test.{ts,tsx}', {cwd})
const modules = files.filter(file => {
return path.basename(file).toLowerCase().includes(filter)
})
if (modules.length === 0) {
console.log(`No tests found for pattern "${filter}"`)
process.exit()
}
const suites = modules
.map(
(m, idx) => `
globalThis.UVU_INDEX = ${idx}
globalThis.UVU_QUEUE.push([${JSON.stringify(path.basename(m))}])
await import(${JSON.stringify('./' + m)})
`
)
.join('\n')
const entry = `
const {exec} = await import('uvu')
globalThis.UVU_DEFER = 1;
${suites}
exec().catch(error => {
console.error(error.stack || error.message)
process.exit(1)
})
`
const external = findNodeModules(process.cwd())
const outfile = path.posix.join(
process.cwd(),
'node_modules',
crypto.randomBytes(16).toString('hex') + '.mjs'
)
await esbuild.build({
bundle: true,
format: 'esm',
platform: 'node',
external,
outfile,
banner: {
js: `import "data:text/javascript,process.argv.push('.bin/uvu')" // Trigger isCLI`
},
stdin: {
contents: entry,
resolveDir: process.cwd(),
sourcefile: 'test.js'
}
})
await import(`file://${outfile}`).finally(() => fs.promises.unlink(outfile))
}
}
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
node-version: '18'
- uses: actions/cache@v3
with:
path: |
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"start": "next start"
},
"dependencies": {
"@alinea/content": "link:.alinea",
"@alinea/generated": "link:.alinea",
"alinea": "0.0.0",
"include-media": "^1.4.10",
"next": "^12.2.5",
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/src/pages/api/preview.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {backend} from '@alinea/content/backend'
import {backend} from '@alinea/generated/backend'
import type {NextApiRequest, NextApiResponse} from 'next'

export default async function handler(
Expand Down
7 changes: 3 additions & 4 deletions apps/demo/src/pages/home.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {Pages} from '@alinea/content'
import {initPages} from '@alinea/content/pages'
import {Store} from 'alinea/store'
import {Pages} from '@alinea/generated'
import {initPages} from '@alinea/generated/pages'
import {GetStaticPropsContext} from 'next'
import {DemoHome} from '../view/home/DemoHome'

Expand All @@ -26,6 +25,6 @@ export async function queryHome(pages: Pages) {
return {...home, recipes}
}

export type HomeProps = Store.TypeOf<ReturnType<typeof queryHome>>
export type HomeProps = Awaited<ReturnType<typeof queryHome>>

export default DemoHome
4 changes: 2 additions & 2 deletions apps/demo/src/pages/recipes/[slug].tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Pages} from '@alinea/content'
import {initPages} from '@alinea/content/pages'
import {Pages} from '@alinea/generated'
import {initPages} from '@alinea/generated/pages'
import {GetStaticPropsContext} from 'next'
import {Recipe} from '../../view/recipe/Recipe'

Expand Down
4 changes: 2 additions & 2 deletions apps/demo/src/pages/recipes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Pages} from '@alinea/content'
import {initPages} from '@alinea/content/pages'
import {Pages} from '@alinea/generated'
import {initPages} from '@alinea/generated/pages'
import {GetStaticPropsContext} from 'next'
import {DemoRecipes} from '../../view/recipes/DemoRecipes'

Expand Down
6 changes: 3 additions & 3 deletions apps/demo/src/view/Demo.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {config} from '@alinea/content/config'
import {createStore} from '@alinea/content/store'
import {config} from '@alinea/generated/config'
import {createStore} from '@alinea/generated/store'
import {JWTPreviews, Server} from 'alinea/backend'
import {IndexedDBData, IndexedDBDrafts} from 'alinea/backend/indexeddb'
import {Dashboard, Preview} from 'alinea/dashboard'
Expand Down Expand Up @@ -157,7 +157,7 @@ function createDemo() {
client,
session: {
user: {sub: 'anonymous'},
hub: client,
cnx: client,
end: async () => {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/src/view/home/DemoHome.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Page} from '@alinea/content'
import {Page} from '@alinea/generated'
import {fromModule, VStack} from 'alinea/ui'
import {DemoHeader} from '../layout/DemoHeader'
import {DemoLayout} from '../layout/DemoLayout'
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/src/view/recipe/Recipe.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Page} from '@alinea/content'
import {Page} from '@alinea/generated'
import {fromModule} from 'alinea/ui'
import {DemoHeader} from '../layout/DemoHeader'
import {DemoLayout} from '../layout/DemoLayout'
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/src/view/recipes/DemoRecipes.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Page} from '@alinea/content'
import {Page} from '@alinea/generated'
import {fromModule} from 'alinea/ui'
import css from './DemoRecipes.module.scss'

Expand Down
6 changes: 3 additions & 3 deletions apps/web/content/data/docs/content/intro.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"content": [
{
"type": "text",
"text": "A Javascript library is generated inside the `.alinea` folder which allows us to interact with the content in JavaScript. It is linked via the `@alinea/content` package name."
"text": "A Javascript library is generated inside the `.alinea` folder which allows us to interact with the content in JavaScript. It is linked via the `@alinea/generated` package name."
}
]
}
Expand All @@ -102,7 +102,7 @@
{
"id": "28hnf59Rd5Gbite3NVvsvobRTZz",
"type": "CodeBlock",
"code": "// Published content is stored in json files \n// inside the content directory\ncontent\n├ data // data root\n│ ├ index.json\n│ ├ blog.json\n│ ╰ blog\n│ ├ blog-post.json\n│ ╰ another-blog-post.json\n╰ media // media root\n ├ image.png.json\n ╰ file.pdf.json\n\n// A folder which is publicly available\npublic\n╰ media\n ├ image.png\n ╰ file.pdf\n\n// The alinea directory exports a Javascript library\n// which can be imported from @alinea/content\n.alinea\n├ ...\n├ pages.js\n├ schema.js\n╰ backend.js",
"code": "// Published content is stored in json files \n// inside the content directory\ncontent\n├ data // data root\n│ ├ index.json\n│ ├ blog.json\n│ ╰ blog\n│ ├ blog-post.json\n│ ╰ another-blog-post.json\n╰ media // media root\n ├ image.png.json\n ╰ file.pdf.json\n\n// A folder which is publicly available\npublic\n╰ media\n ├ image.png\n ╰ file.pdf\n\n// The alinea directory exports a Javascript library\n// which can be imported from @alinea/generated\n.alinea\n├ ...\n├ pages.js\n├ schema.js\n╰ backend.js",
"compact": true
}
]
Expand All @@ -111,4 +111,4 @@
"alinea": {
"index": "a0"
}
}
}
4 changes: 2 additions & 2 deletions apps/web/content/data/docs/content/pages.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
{
"id": "KSTSIoTMXMiTf6PYZeqZ6",
"type": "CodeBlock",
"code": "import {initPages} from '@alinea/content/pages'\n\n// The initPages method also accepts a previewToken to query\n// drafts while previewing, see the next chapter on how to obtain one\nconst pages = initPages()"
"code": "import {initPages} from '@alinea/generated/pages'\n\n// The initPages method also accepts a previewToken to query\n// drafts while previewing, see the next chapter on how to obtain one\nconst pages = initPages()"
},
{
"type": "heading",
Expand Down Expand Up @@ -136,7 +136,7 @@
{
"id": "IEmT75lZgxznL9v7Zq9mW",
"type": "CodeBlock",
"code": "import {initPages} from '@alinea/content/pages'\n\nconst old = await pages.whereType('Animal').where(\n animal => animal.age.greater(10)\n)\nconst teenager = await pages.whereType('Human').where(\n human => \n human.age.greater(10).or(\n human.age.less(20)\n )\n)\nconst applesOrOranges = await pages.whereType('Fruit').where(\n fruit => fruit.title.isIn(['apple', 'orange'])\n)"
"code": "import {initPages} from '@alinea/generated/pages'\n\nconst old = await pages.whereType('Animal').where(\n animal => animal.age.greater(10)\n)\nconst teenager = await pages.whereType('Human').where(\n human => \n human.age.greater(10).or(\n human.age.less(20)\n )\n)\nconst applesOrOranges = await pages.whereType('Fruit').where(\n fruit => fruit.title.isIn(['apple', 'orange'])\n)"
},
{
"type": "heading",
Expand Down
2 changes: 1 addition & 1 deletion apps/web/content/data/docs/content/typescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
{
"id": "W2NnQtGHkU2m958whlPt_",
"type": "CodeBlock",
"code": "import {Page} from '@alinea/content'"
"code": "import {Page} from '@alinea/generated'"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"type": "Variant",
"name": "Next.js serverless",
"language": "tsx",
"code": "// pages/api/cms/[...slug].ts\n\n// The nodeHandler utility exports the backend handle as a Node.js http handler\nimport {nodeHandler} from 'alinea/backend/router/NodeHandler'\n// The generated backend file will connect to the backend we'll configure next\nimport {backend} from '@alinea/content/backend.js'\n// Handle cms API routes at /api/cms/[...slug]\nexport default nodeHandler(backend.handle)\n// Disable the body parser middleware that next.js injects,\n// we'll let the handler deal with it\nexport const config = {api: {bodyParser: false}}"
"code": "// pages/api/cms/[...slug].ts\n\n// The nodeHandler utility exports the backend handle as a Node.js http handler\nimport {nodeHandler} from 'alinea/backend/router/NodeHandler'\n// The generated backend file will connect to the backend we'll configure next\nimport {backend} from '@alinea/generated/backend.js'\n// Handle cms API routes at /api/cms/[...slug]\nexport default nodeHandler(backend.handle)\n// Disable the body parser middleware that next.js injects,\n// we'll let the handler deal with it\nexport const config = {api: {bodyParser: false}}"
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions apps/web/content/data/docs/intro.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@
"content": [
{
"type": "text",
"text": "Alinea indexes the JSON files into an embedded SQLite database. Having a database with indexed fields means querying content is fast and simple. The database and tools to query content are packaged into a Javascript library that sits next to your code and is aliased to `@alinea/content`."
"text": "Alinea indexes the JSON files into an embedded SQLite database. Having a database with indexed fields means querying content is fast and simple. The database and tools to query content are packaged into a Javascript library that sits next to your code and is aliased to `@alinea/generated`."
}
]
},
{
"id": "AaQPYG-vXDXCcb-40iYeP",
"type": "CodeBlock",
"code": "import {initPages} from '@alinea/content/pages'\nconst pages = initPages()\nconsole.log(\n await pages\n .whereType('BlogPost')\n .where(post => post.author.is('Me'))\n .select(post => ({title: post.title}))\n)"
"code": "import {initPages} from '@alinea/generated/pages'\nconst pages = initPages()\nconsole.log(\n await pages\n .whereType('BlogPost')\n .where(post => post.author.is('Me'))\n .select(post => ({title: post.title}))\n)"
},
{
"id": "Gs_7cGVP61b0kBG9DKV7u",
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
{
"id": "-tfrsrqfkY0Z903mpkZnx",
"type": "CodeBlock",
"code": "import {backend} from '@alinea/content/backend.js'\nimport type {NextApiRequest, NextApiResponse} from 'next'\n\nexport default async function handler(\n req: NextApiRequest,\n res: NextApiResponse\n) {\n // We'll parse the previewToken from the url /api/preview?token\n const previewToken = req.url!.split('?').pop()\n\n // We can ask alinea to parse and validate the preview token.\n // We'll receive the url of the entry we're currently previewing.\n const {url} = await backend.parsePreviewToken(previewToken)\n \n // Store the preview token in the Next.js context so we\n // can use it in the next route to query drafts data. Next.js\n // uses a temporary cookie to persist this.\n res.setPreviewData(previewToken)\n\n // Finally redirect to the page we actually want to view\n res.redirect(url)\n}",
"code": "import {backend} from '@alinea/generated/backend.js'\nimport type {NextApiRequest, NextApiResponse} from 'next'\n\nexport default async function handler(\n req: NextApiRequest,\n res: NextApiResponse\n) {\n // We'll parse the previewToken from the url /api/preview?token\n const previewToken = req.url!.split('?').pop()\n\n // We can ask alinea to parse and validate the preview token.\n // We'll receive the url of the entry we're currently previewing.\n const {url} = await backend.parsePreviewToken(previewToken)\n \n // Store the preview token in the Next.js context so we\n // can use it in the next route to query drafts data. Next.js\n // uses a temporary cookie to persist this.\n res.setPreviewData(previewToken)\n\n // Finally redirect to the page we actually want to view\n res.redirect(url)\n}",
"fileName": "pages/api/preview.ts"
},
{
Expand All @@ -116,7 +116,7 @@
{
"id": "qQxOBtOwIiLwZsZXhGYN9",
"type": "CodeBlock",
"code": "import {initPages} from '@alinea/content/pages'\nimport {GetStaticPropsContext} from 'next'\n\nexport async function getStaticProps(context: GetStaticPropsContext) {\n // Pass the previewToken that we receive in previewData to initPages\n const pages = initPages(context.previewData as string)\n\n // Anything we query on this pages instance will reflect drafts data\n const recipe = await pages.whereType('Recipe').first(page => page.path.is(slug))\n return {props: recipe}\n}\n\nexport default RecipeView",
"code": "import {initPages} from '@alinea/generated/pages'\nimport {GetStaticPropsContext} from 'next'\n\nexport async function getStaticProps(context: GetStaticPropsContext) {\n // Pass the previewToken that we receive in previewData to initPages\n const pages = initPages(context.previewData as string)\n\n // Anything we query on this pages instance will reflect drafts data\n const recipe = await pages.whereType('Recipe').first(page => page.path.is(slug))\n return {props: recipe}\n}\n\nexport default RecipeView",
"fileName": "pages/recipe/[slug].tsx"
},
{
Expand Down
Loading