Skip to content

Commit 22cc475

Browse files
PuruVJbenmccann
andauthored
feat(site): site-kit renderer (#8757)
* Push * Weirdass fix * Unified renderer * Move a bit * Accomodate to new renderer * update site-kit * bump site-kit * Fix script * Bump site-kit --------- Co-authored-by: Ben McCann <[email protected]>
1 parent cf32fa2 commit 22cc475

File tree

18 files changed

+134
-1416
lines changed

18 files changed

+134
-1416
lines changed

documentation/blog/2017-09-06-the-zen-of-just-writing-css.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ Let's see what that looks like in practice.
4444
<source type='video/mp4' src='https://svelte-technology-assets.surge.sh/just-write-css.mp4'>
4545
</video>
4646

47-
<figcaption>
48-
Is this what they mean by 'use the platform'?
49-
</figcaption>
47+
<!-- prettier-ignore -->
48+
<figcaption>
49+
Is this what they mean by 'use the platform'?
50+
</figcaption>
5051

5152
</figure>
5253

documentation/docs/03-runtime/02-svelte-store.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Note that the value of a `writable` is lost when it is destroyed, for example wh
6262
Creates a store whose value cannot be set from 'outside', the first argument is the store's initial value, and the second argument to `readable` is the same as the second argument to `writable`.
6363

6464
```js
65+
<!--- file: App.svelte --->
6566
// ---cut---
6667
import { readable } from 'svelte/store';
6768

pnpm-lock.yaml

Lines changed: 16 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sites/svelte.dev/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"@resvg/resvg-js": "^2.4.1",
3131
"@sveltejs/adapter-vercel": "^3.0.1",
3232
"@sveltejs/kit": "^1.20.4",
33-
"@sveltejs/site-kit": "6.0.0-next.8",
33+
"@sveltejs/site-kit": "6.0.0-next.11",
3434
"@sveltejs/vite-plugin-svelte": "^2.4.1",
3535
"@types/marked": "^5.0.0",
3636
"@types/node": "^20.3.1",

sites/svelte.dev/scripts/type-gen/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function munge_type_element(member, depth = 1) {
146146
// @ts-ignore
147147
const doc = member.jsDoc?.[0];
148148

149-
if (/private api/i.test(doc?.comment)) return;
149+
if (/(private api|do not use)/i.test(doc?.comment)) return;
150150

151151
/** @type {string[]} */
152152
const children = [];
@@ -304,7 +304,7 @@ fs.writeFileSync(
304304
`
305305
/* This file is generated by running \`pnpm generate\`
306306
in the sites/svelte.dev directory — do not edit it */
307-
export const modules = /** @type {import('../generated/types').Modules} */ (${JSON.stringify(
307+
export const modules = /** @type {import('@sveltejs/site-kit/markdown').Modules} */ (${JSON.stringify(
308308
modules,
309309
null,
310310
' '

sites/svelte.dev/src/lib/generated/types.d.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

sites/svelte.dev/src/lib/server/blog/index.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
// @ts-check
2-
import { modules } from '$lib/generated/type-info.js';
2+
import { extractFrontmatter } from '@sveltejs/site-kit/markdown';
33
import fs from 'node:fs';
44
import { CONTENT_BASE_PATHS } from '../../../constants.js';
5-
import { extract_frontmatter } from '../markdown/index.js';
6-
import { render_markdown } from '../markdown/renderer.js';
5+
import { render_content } from '../renderer.js';
76

87
/**
98
* @param {import('./types').BlogData} blog_data
109
* @param {string} slug
1110
*/
1211
export async function get_processed_blog_post(blog_data, slug) {
13-
const post = blog_data.find((post) => post.slug === slug);
14-
15-
if (!post) return null;
12+
for (const post of blog_data) {
13+
if (post.slug === slug) {
14+
return {
15+
...post,
16+
content: await render_content(post.file, post.content)
17+
};
18+
}
19+
}
1620

17-
return {
18-
...post,
19-
content: await render_markdown(post.file, post.content, { modules })
20-
};
21+
return null;
2122
}
2223

2324
const BLOG_NAME_REGEX = /^(\d{4}-\d{2}-\d{2})-(.+)\.md$/;
@@ -31,7 +32,7 @@ export function get_blog_data(base = CONTENT_BASE_PATHS.BLOG) {
3132
if (!BLOG_NAME_REGEX.test(file)) continue;
3233

3334
const { date, date_formatted, slug } = get_date_and_slug(file);
34-
const { metadata, body } = extract_frontmatter(fs.readFileSync(`${base}/${file}`, 'utf-8'));
35+
const { metadata, body } = extractFrontmatter(fs.readFileSync(`${base}/${file}`, 'utf-8'));
3536

3637
blog_posts.push({
3738
date,

sites/svelte.dev/src/lib/server/docs/index.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { base as app_base } from '$app/paths';
22
import { modules } from '$lib/generated/type-info.js';
3-
import fs from 'node:fs';
4-
import { CONTENT_BASE_PATHS } from '../../../constants.js';
53
import {
64
escape,
7-
extract_frontmatter,
5+
extractFrontmatter,
6+
markedTransform,
87
normalizeSlugify,
98
removeMarkdown,
10-
transform
11-
} from '../markdown/index.js';
12-
import { render_markdown } from '../markdown/renderer.js';
9+
replaceExportTypePlaceholders
10+
} from '@sveltejs/site-kit/markdown';
11+
import fs from 'node:fs';
12+
import { CONTENT_BASE_PATHS } from '../../../constants.js';
13+
import { render_content } from '../renderer';
1314

1415
/**
1516
* @param {import('./types').DocsData} docs_data
@@ -21,7 +22,7 @@ export async function get_parsed_docs(docs_data, slug) {
2122
if (page.slug === slug) {
2223
return {
2324
...page,
24-
content: await render_markdown(page.file, page.content, { modules })
25+
content: await render_content(page.file, page.content)
2526
};
2627
}
2728
}
@@ -62,7 +63,7 @@ export function get_docs_data(base = CONTENT_BASE_PATHS.DOCS) {
6263

6364
const page_slug = match[1].replace('.md', '');
6465

65-
const page_data = extract_frontmatter(
66+
const page_data = extractFrontmatter(
6667
fs.readFileSync(`${base}/${category_dir}/${filename}`, 'utf-8')
6768
);
6869

@@ -105,10 +106,12 @@ function get_sections(markdown) {
105106
const secondLevelHeadings = [];
106107
let match;
107108

108-
while ((match = headingRegex.exec(markdown)) !== null) {
109+
const placeholders_rendered = replaceExportTypePlaceholders(markdown, modules);
110+
111+
while ((match = headingRegex.exec(placeholders_rendered)) !== null) {
109112
secondLevelHeadings.push({
110113
title: removeMarkdown(
111-
escape(transform(match[1], { paragraph: (txt) => txt }))
114+
escape(markedTransform(match[1], { paragraph: (txt) => txt }))
112115
.replace(/<\/?code>/g, '')
113116
.replace(/&#39;/g, "'")
114117
.replace(/&quot;/g, '"')

sites/svelte.dev/src/lib/server/examples/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ import fs from 'node:fs';
66
* @param {string} slug
77
*/
88
export function get_example(examples_data, slug) {
9-
const example = examples_data
10-
.find((section) => section.examples.find((example) => example.slug === slug))
11-
?.examples.find((example) => example.slug === slug);
9+
for (const section of examples_data) {
10+
for (const example of section.examples) {
11+
if (example.slug === slug) {
12+
return example;
13+
}
14+
}
15+
}
1216

13-
return example;
17+
return null;
1418
}
1519

1620
/**

0 commit comments

Comments
 (0)