Skip to content

Commit

Permalink
🔥 publish
Browse files Browse the repository at this point in the history
  • Loading branch information
shiki-01 committed Feb 8, 2025
1 parent cf6844b commit e5e5651
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
36 changes: 28 additions & 8 deletions src/routes/[lesson]/[id]/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PageServerLoad } from "./$types";
import { render } from 'svelte/server';
import { rewriteTags } from "$lib/utils/rewrite";
import type { EntryGenerator, PageServerLoad, RouteParams } from './$types';
import type { Component } from 'svelte';
import { render } from 'svelte/server';
import { rewriteTags } from '$lib/utils/rewrite';

interface PageModule {
default: unknown;
Expand All @@ -25,14 +25,14 @@ const loadPage = async (lesson: string, id: string) => {

let renderHtml = render(pageModule as unknown as Component, {});

const terms = await import(`\$lib/docs/${lesson}/terms/index.json`)
const terms = await import(`\$lib/docs/${lesson}/terms/index.json`);

renderHtml.body = rewriteTags(renderHtml.body, terms.default, lesson)
renderHtml.body = rewriteTags(renderHtml.body, terms.default, lesson);

return {
component: pageModule.default,
html: renderHtml,
title: pageModule.metadata?.title || '',
title: pageModule.metadata?.title || ''
};
};

Expand All @@ -45,7 +45,27 @@ export const load: PageServerLoad = async ({ params }) => {
props: {
lesson,
id,
lessonHtml,
lessonHtml
}
};
};
};

export const entries: EntryGenerator = async (): Promise<Array<{ lesson: string; id: string }>> => {
const pagesAll = import.meta.glob('/src/lib/docs/*/lessons/*/index.svx', { eager: true });

// 重複しないキー("lesson/id" 形式)を作成
const uniqueKeys: Record<string, true> = Object.keys(pagesAll).reduce((acc, filePath) => {
const parts = filePath.split('/');
const lesson = parts[4];
const id = parts[6];
const key = `${lesson}/${id}`;
acc[key] = true;
return acc;
}, {} as Record<string, true>);

// キーを分割してパラメーターオブジェクトを生成
return Object.keys(uniqueKeys).map((key) => {
const [lesson, id] = key.split('/');
return { lesson, id };
});
};
2 changes: 1 addition & 1 deletion static/CNAME
Original file line number Diff line number Diff line change
@@ -1 +1 @@
misc-lesson.f5.si
misc-lessons.f5.si

0 comments on commit e5e5651

Please sign in to comment.