chore(site): fix build (#8762)

* fix: 404 instead of 500
* omit legacy entrypoints
* fix prefetch
pull/8480/head
gtmnayan 2 years ago committed by GitHub
parent 54f72f4545
commit f8139e5a6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -36,7 +36,7 @@ To make that possible we first needed to rethink the concept at the heart of mod
In old Svelte, you would tell the computer that some state had changed by calling the `this.set` method: In old Svelte, you would tell the computer that some state had changed by calling the `this.set` method:
```js ```js
// @errors: 7017 // @noErrors
const { count } = this.get(); const { count } = this.get();
this.set({ this.set({
count: count + 1 count: count + 1
@ -46,7 +46,7 @@ this.set({
That would cause the component to _react_. Speaking of which, `this.set` is almost identical to the `this.setState` method used in classical (pre-hooks) React: That would cause the component to _react_. Speaking of which, `this.set` is almost identical to the `this.setState` method used in classical (pre-hooks) React:
```js ```js
// @errors: 7017 // @noErrors
const { count } = this.state; const { count } = this.state;
this.setState({ this.setState({
count: count + 1 count: count + 1

@ -2,7 +2,6 @@
"name": "svelte.dev", "name": "svelte.dev",
"private": true, "private": true,
"version": "1.0.0", "version": "1.0.0",
"private": true,
"description": "Docs and examples for Svelte", "description": "Docs and examples for Svelte",
"type": "module", "type": "module",
"scripts": { "scripts": {

@ -257,7 +257,12 @@ function read_d_ts_file(file) {
// @ts-ignore // @ts-ignore
const name = statement.name.text || statement.name.escapedText; const name = statement.name.text || statement.name.escapedText;
if (name === '*.svelte' || name === 'svelte/types/compiler/preprocess') { const ignore_list = [
'*.svelte',
'svelte/types/compiler/preprocess', // legacy entrypoints, omit from docs
'svelte/types/compiler/interfaces' // legacy entrypoints, omit from docs
];
if (ignore_list.includes(name)) {
continue; continue;
} }

@ -29,7 +29,7 @@
%sveltekit.head% %sveltekit.head%
</head> </head>
<body data-sveltekit-prefetch> <body data-sveltekit-preload-code="hover">
<div>%sveltekit.body%</div> <div>%sveltekit.body%</div>
</body> </body>
</html> </html>

@ -16,16 +16,18 @@ import { render_markdown } from '../markdown/renderer.js';
* @param {string} slug * @param {string} slug
*/ */
export async function get_parsed_docs(docs_data, slug) { export async function get_parsed_docs(docs_data, slug) {
const page = docs_data for (const { pages } of docs_data) {
.find(({ pages }) => pages.find((page) => slug === page.slug)) for (const page of pages) {
?.pages.find((page) => slug === page.slug); if (page.slug === slug) {
return {
if (!page) return null; ...page,
content: await render_markdown(page.file, page.content, { modules })
};
}
}
}
return { return null;
...page,
content: await render_markdown(page.file, page.content, { modules })
};
} }
/** @return {import('./types').DocsData} */ /** @return {import('./types').DocsData} */
@ -53,16 +55,15 @@ export function get_docs_data(base = CONTENT_BASE_PATHS.DOCS) {
pages: [] pages: []
}; };
for (const page_md of fs for (const filename of fs.readdirSync(`${base}/${category_dir}`)) {
.readdirSync(`${base}/${category_dir}`) if (filename === 'meta.json') continue;
.filter((filename) => filename !== 'meta.json')) { const match = /\d{2}-(.+)/.exec(filename);
const match = /\d{2}-(.+)/.exec(page_md);
if (!match) continue; if (!match) continue;
const page_slug = match[1].replace('.md', ''); const page_slug = match[1].replace('.md', '');
const page_data = extract_frontmatter( const page_data = extract_frontmatter(
fs.readFileSync(`${base}/${category_dir}/${page_md}`, 'utf-8') fs.readFileSync(`${base}/${category_dir}/${filename}`, 'utf-8')
); );
if (page_data.metadata.draft === 'true') continue; if (page_data.metadata.draft === 'true') continue;
@ -76,7 +77,7 @@ export function get_docs_data(base = CONTENT_BASE_PATHS.DOCS) {
content: page_content, content: page_content,
sections: get_sections(page_content), sections: get_sections(page_content),
path: `${app_base}/docs/${page_slug}`, path: `${app_base}/docs/${page_slug}`,
file: `${category_dir}/${page_md}` file: `${category_dir}/${filename}`
}); });
} }

@ -4,7 +4,7 @@ import { error } from '@sveltejs/kit';
export const prerender = true; export const prerender = true;
export async function load({ params }) { export async function load({ params }) {
const processed_page = get_parsed_docs(get_docs_data(), params.slug); const processed_page = await get_parsed_docs(get_docs_data(), params.slug);
if (!processed_page) throw error(404); if (!processed_page) throw error(404);

Loading…
Cancel
Save