Skip to content

Commit 2fceb10

Browse files
fix: skip building faq.json when faq.yml is empty
1 parent 22673da commit 2fceb10

3 files changed

Lines changed: 18 additions & 16 deletions

File tree

afterpython/_website/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@afterpython/project-website-template",
3-
"version": "0.3.1",
3+
"version": "0.3.2",
44
"license": "Apache-2.0",
55
"type": "module",
66
"scripts": {
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { error } from '@sveltejs/kit';
21
import type { PageServerLoad } from './$types';
32

43
export const prerender = true;
@@ -9,11 +8,13 @@ type FaqItem = {
98
category?: string;
109
};
1110

11+
const FILE = 'faq' as const;
12+
1213
export const load: PageServerLoad = async () => {
1314
try {
14-
const faq = await import('$static/faq.json');
15+
const faq = await import(`$static/${FILE}.json`);
1516
return { faq: (faq.default ?? faq) as FaqItem[] };
1617
} catch {
17-
throw error(404, 'FAQs are not available for this project.');
18+
return { faq: [] as FaqItem[] };
1819
}
1920
};

src/afterpython/builders/faq_json.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,21 @@ def build_faq_json():
2424
click.echo("No faq.yml found, skip building faq.json")
2525
return
2626

27-
click.echo("Building faq.json...")
28-
2927
raw = read_yaml(faq_yml_path)
3028
if raw is None:
31-
items: list[dict] = []
32-
else:
33-
items = [
34-
{
35-
"question": str(item["question"]),
36-
"answer": str(item["answer"]),
37-
"category": str(item["category"]) if item.get("category") else "",
38-
}
39-
for item in raw
40-
]
29+
click.echo("faq.yml is empty, skip building faq.json")
30+
return
31+
32+
click.echo("Building faq.json...")
33+
34+
items = [
35+
{
36+
"question": str(item["question"]),
37+
"answer": str(item["answer"]),
38+
"category": str(item["category"]) if item.get("category") else "",
39+
}
40+
for item in raw
41+
]
4142

4243
with open(build_path / "faq.json", "w") as f:
4344
json.dump(items, f, indent=2)

0 commit comments

Comments
 (0)