Skip to content

Commit 53cc891

Browse files
authored
chore: update svelte kit to v1.0.0-next.406 (#229)
1 parent 6602d70 commit 53cc891

15 files changed

+103
-59
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@
1717
/docs-svelte-kit/shim/eslint.mjs
1818
/docs-svelte-kit/shim/assert.mjs
1919
!/.*.js
20+
/docs-svelte-kit/src/routes/*.md
21+
/docs-svelte-kit/src/routes/**/*.md

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,5 @@ dist
109109
/svelte.config-dist.js
110110
/docs-svelte-kit/shim/eslint.mjs
111111
/docs-svelte-kit/shim/assert.mjs
112+
/docs-svelte-kit/src/routes/*.md
113+
/docs-svelte-kit/src/routes/**/*.md

docs-svelte-kit/src/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ module.exports = {
55
rules: {
66
"node/no-unsupported-features/es-syntax": "off",
77
"require-jsdoc": "off",
8+
"node/no-missing-import": "off",
89
},
910
}

docs-svelte-kit/src/lib/utils.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { rules } from "../../../src/utils/rules.ts"
22
import { readable, writable } from "svelte/store"
3-
// eslint-disable-next-line node/no-missing-import -- ignore
43
import { page } from "$app/stores"
5-
// eslint-disable-next-line node/no-missing-import -- ignore
64
import { base as baseUrl } from "$app/paths"
75

86
export function stripBaseUrl(path) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script>
2+
import { base as baseUrl } from "$app/paths"
3+
import { page } from "$app/stores"
4+
</script>
5+
6+
<h1>{$page.status}</h1>
7+
<blockquote>
8+
<p>{$page.error.message}</p>
9+
<p>Take me <a href="{baseUrl}/">home</a></p>
10+
</blockquote>

docs-svelte-kit/src/routes/+layout.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { markdownPath } from "$lib/utils.js"
2+
const docs = import.meta.glob("../../../docs/**/*.md")
3+
4+
/** @type {import('@sveltejs/kit').Load} */
5+
export async function load({ url }) {
6+
const markdown = `../../../docs/${markdownPath(url.pathname)}`
7+
if (docs[markdown]) {
8+
return {
9+
moduleData: await docs[markdown](),
10+
}
11+
}
12+
13+
// 404
14+
return {
15+
moduleData: {
16+
frontmatter: { title: "404", hiddenMenu: true },
17+
},
18+
}
19+
}

docs/__layout.svelte renamed to docs-svelte-kit/src/routes/+layout.svelte

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,15 @@
1-
<script context="module">
2-
import { markdownPath } from "$lib/utils.js"
3-
const docs = import.meta.glob("./**/*.md")
4-
5-
/** @type {import('@sveltejs/kit').Load} */
6-
export async function load({ url }) {
7-
const markdown = `./${markdownPath(url.pathname)}`
8-
if (docs[markdown]) {
9-
return {
10-
props: {
11-
moduleData: await docs[markdown](),
12-
},
13-
}
14-
}
15-
16-
// 404
17-
return {
18-
props: {
19-
moduleData: {
20-
frontmatter: { title: "404", hiddenMenu: true },
21-
},
22-
},
23-
}
24-
}
25-
</script>
26-
271
<script>
282
import Header from "$lib/header/Header.svelte"
293
import SideMenu from "$lib/sidemenu/SideMenu.svelte"
304
import Footer from "$lib/footer/Footer.svelte"
315
32-
import "../docs-svelte-kit/src/app.css"
33-
import "../docs-svelte-kit/src/site.css"
6+
import "../app.css"
7+
import "../site.css"
348
import { tocStore } from "$lib/utils"
359
36-
export let moduleData
37-
10+
/** @type {import('./$types').PageData */
11+
export let data
12+
$: ({ moduleData } = data)
3813
$: frontmatter = moduleData.frontmatter
3914
$: fileInfo = moduleData.fileInfo
4015
$: {
File renamed without changes.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import path from "path"
2+
import fs from "fs"
3+
import { fileURLToPath } from "url"
4+
const dirname = path.dirname(
5+
fileURLToPath(
6+
// @ts-expect-error -- Cannot change `module` option
7+
import.meta.url,
8+
),
9+
)
10+
11+
/** Generate svelte kit routes files */
12+
export default function generateRoutes(): void {
13+
const srcRoot = path.join(dirname, "../../docs")
14+
const distRoot = path.join(dirname, "../src/routes")
15+
16+
for (const markdownPath of iterateMarkdown(srcRoot)) {
17+
const markdownRelativePath = path.relative(srcRoot, markdownPath)
18+
const distPath = path.join(
19+
distRoot,
20+
markdownRelativePath.replace(/(?:README)?\.md$/u, "/+page.md"),
21+
)
22+
23+
mkdirs(path.dirname(distPath))
24+
fs.writeFileSync(
25+
distPath,
26+
`<script>
27+
import MD from "${path.relative(path.dirname(distPath), markdownPath)}"
28+
</script>
29+
30+
<MD />
31+
`,
32+
"utf-8",
33+
)
34+
}
35+
}
36+
37+
/** Iterate markdown files */
38+
function* iterateMarkdown(rootDir: string): IterableIterator<string> {
39+
for (const filename of fs.readdirSync(rootDir)) {
40+
const abs = path.join(rootDir, filename)
41+
if (path.extname(filename) === ".md") {
42+
yield abs
43+
} else if (fs.statSync(abs).isDirectory()) {
44+
yield* iterateMarkdown(abs)
45+
}
46+
}
47+
}
48+
49+
/** Make directories */
50+
function mkdirs(dir: string): void {
51+
if (!fs.existsSync(dir)) {
52+
mkdirs(path.dirname(dir))
53+
fs.mkdirSync(dir)
54+
}
55+
}

docs-svelte-kit/tools/markdown-it-replace-link.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ export default (md: Md, options: { baseUrl: string; root: string }): void => {
2424

2525
return `${base}/${path
2626
.relative(root, absolutePath)
27-
.replace(/\.md$/, "")}/${hash}`.replace(/\\/gu, "/")
27+
.replace(/README\.md$/, "")
28+
.replace(/\.md$/, "")}/${hash}`
29+
.replace(/\\/gu, "/")
30+
.replace(/\/+/gu, "/")
2831
}
2932

3033
md.renderer.rules.link_open = (tokens, idx, options, env, self) => {

0 commit comments

Comments
 (0)