Skip to content

Commit

Permalink
Sveltekit slug entry names are autogenerated
Browse files Browse the repository at this point in the history
  • Loading branch information
ironkayman committed Jan 24, 2024
1 parent daebad9 commit efcf4fd
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/routes/(mawanet)/mawanet/[[entry]]/+page.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import { fetchComponent } from "$lib/stores/mawanet.loader.js"

export async function load({ params }) {
Expand All @@ -8,3 +9,25 @@ export async function load({ params }) {
error: entryProperties.error,
};
}


/** @type {import('./$types').EntryGenerator} */
export function entries() {
return [

{ entry: 'maelstrom_encyclopedia' },
{ entry: 'engine_of_narraphysic_gliding' },
{ entry: 'resonance' },
{ entry: 'vacuum_ascention' },
{ entry: 'accursed_framework' },
{ entry: 'conceptual_configuration' },
{ entry: 'altered_field_presence' },
{ entry: 'narraphysic_realm' },
{ entry: 'retroactive_refractory_feedback_loop' },
{ entry: 'narraphysic_isolation_environment' },
{ entry: 'narrative' },
{ entry: 'superimposition_event' },
];
}

export const prerender = true;
43 changes: 43 additions & 0 deletions tools/mdx_hierarcher/mdx_hierarcher/glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,37 @@
break;
"""


_PAGE_JS_PATH = "src/routes/(mawanet)/mawanet/[[entry]]/+page.js"

_PAGE_JS_BEGIN = """
import { fetchComponent } from "$lib/stores/mawanet.loader.js"
export async function load({ params }) {
let entryProperties = await fetchComponent(params.entry ?? 'index')
return {
pageName: entryProperties.componentName,
pageComponent: entryProperties.entryComponent,
error: entryProperties.error,
};
}
/** @type {import('./$types').EntryGenerator} */
export function entries() {
return [
"""

_PAGE_JS_ENTRY_PATTERN = """
{ entry: '%s' },"""

_PAGE_JS_END = """
];
}
export const prerender = true;
"""

class Globber:

_RE_WIKILINK: Pattern = re_compile(
Expand Down Expand Up @@ -106,21 +137,33 @@ def __call__(self) -> Any:

glob_result: Generator = self._glob_root.glob('**/*.md')
count = 0

entry_names = []

for count, md in enumerate(glob_result):
if self._whitelist and md.stem not in whileisted_file_stems:
continue
print('processing:', md.stem)

name_normalised: str = md.stem.replace(' ', '_')
entry_names.append(name_normalised)
contents = md.read_text()
with open(
self._output_dir / (name_normalised + '.mdx'),
mode='w',
encoding='utf-8'
) as mdx:
mdx.write(contents)

with open(Path().cwd() / _PAGE_JS_PATH, mode='w', encoding='utf-8') as pjs:
pjs.write(_PAGE_JS_BEGIN)
for name in entry_names:
pjs.write(_PAGE_JS_ENTRY_PATTERN % name)
pjs.write(_PAGE_JS_END)

print(f'{count} files processed')


def replace_wikilinks(self):
"""
Replaces `[[Entry]]`, `[[Entry Whitespaces#id|alias]]` to
Expand Down

0 comments on commit efcf4fd

Please sign in to comment.