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:
```js
// @errors: 7017
// @noErrors
const { count } = this.get();
this.set({
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:
```js
// @errors: 7017
// @noErrors
const { count } = this.state;
this.setState({
count: count + 1

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

@ -257,7 +257,12 @@ function read_d_ts_file(file) {
// @ts-ignore
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;
}

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

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

Loading…
Cancel
Save