docs: add Stackblitz links for examples (#2559)

This commit is contained in:
Anthony Fu 2022-01-07 17:51:01 +08:00 committed by GitHub
parent d45869d6ce
commit 59e5cfea39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 0 deletions

17
examples/README.md Normal file
View File

@ -0,0 +1,17 @@
# Nuxt 3 Examples
| Example | Source | Playground |
|---|---|---|
| `hello-world` | [GitHub](https://github.com/nuxt/framework/tree/main/examples/hello-world) | [Play Online](https://stackblitz.com/github/nuxt/framework/tree/main/examples/hello-world?file=app.vue&terminal=dev) |
| `locale` | [GitHub](https://github.com/nuxt/framework/tree/main/examples/locale) | [Play Online](https://stackblitz.com/github/nuxt/framework/tree/main/examples/locale?file=app.vue&terminal=dev) |
| `module-extend-pages` | [GitHub](https://github.com/nuxt/framework/tree/main/examples/module-extend-pages) | [Play Online](https://stackblitz.com/github/nuxt/framework/tree/main/examples/module-extend-pages?file=app.vue&terminal=dev) |
| `use-async-data` | [GitHub](https://github.com/nuxt/framework/tree/main/examples/use-async-data) | [Play Online](https://stackblitz.com/github/nuxt/framework/tree/main/examples/use-async-data?file=app.vue&terminal=dev) |
| `use-cookie` | [GitHub](https://github.com/nuxt/framework/tree/main/examples/use-cookie) | [Play Online](https://stackblitz.com/github/nuxt/framework/tree/main/examples/use-cookie?file=app.vue&terminal=dev) |
| `use-fetch` | [GitHub](https://github.com/nuxt/framework/tree/main/examples/use-fetch) | [Play Online](https://stackblitz.com/github/nuxt/framework/tree/main/examples/use-fetch?file=app.vue&terminal=dev) |
| `use-meta` | [GitHub](https://github.com/nuxt/framework/tree/main/examples/use-meta) | [Play Online](https://stackblitz.com/github/nuxt/framework/tree/main/examples/use-meta?file=app.vue&terminal=dev) |
| `use-state` | [GitHub](https://github.com/nuxt/framework/tree/main/examples/use-state) | [Play Online](https://stackblitz.com/github/nuxt/framework/tree/main/examples/use-state?file=app.vue&terminal=dev) |
| `with-components` | [GitHub](https://github.com/nuxt/framework/tree/main/examples/with-components) | [Play Online](https://stackblitz.com/github/nuxt/framework/tree/main/examples/with-components?file=app.vue&terminal=dev) |
| `with-composables` | [GitHub](https://github.com/nuxt/framework/tree/main/examples/with-composables) | [Play Online](https://stackblitz.com/github/nuxt/framework/tree/main/examples/with-composables?file=app.vue&terminal=dev) |
| `with-layouts` | [GitHub](https://github.com/nuxt/framework/tree/main/examples/with-layouts) | [Play Online](https://stackblitz.com/github/nuxt/framework/tree/main/examples/with-layouts?file=app.vue&terminal=dev) |
| `with-pages` | [GitHub](https://github.com/nuxt/framework/tree/main/examples/with-pages) | [Play Online](https://stackblitz.com/github/nuxt/framework/tree/main/examples/with-pages?file=app.vue&terminal=dev) |
| `with-wasm` | [GitHub](https://github.com/nuxt/framework/tree/main/examples/with-wasm) | [Play Online](https://stackblitz.com/github/nuxt/framework/tree/main/examples/with-wasm?file=app.vue&terminal=dev) |

View File

@ -0,0 +1,31 @@
import { fileURLToPath } from 'url'
import { promises as fs } from 'fs'
import { resolve } from 'pathe'
async function run () {
const examplesRoot = resolve(fileURLToPath(import.meta.url), '../../examples')
const examples = await fs.readdir(examplesRoot)
const data = await Promise.all(examples.map(async (name) => {
const path = resolve(examplesRoot, name)
if ((await fs.lstat(path)).isFile()) {
return
}
const github = `https://github.com/nuxt/framework/tree/main/examples/${name}`
const stackblitz = `https://stackblitz.com/github/nuxt/framework/tree/main/examples/${name}?file=app.vue&terminal=dev`
return {
name,
path,
github,
stackblitz
}
}))
const table = '| Example | Source | Playground |\n|---|---|---|\n' + data.filter(Boolean).map(i => `| \`${i.name}\` | [GitHub](${i.github}) | [Play Online](${i.stackblitz}) |`).join('\n')
await fs.writeFile(resolve(examplesRoot, 'README.md'), `# Nuxt 3 Examples\n\n${table}\n`, 'utf-8')
}
run()