Changes
12 changed files (+90/-44)
-
-
@@ -51,7 +51,7 @@ jobs:path: ${{ env.DENO_DIR }} key: deploy-${{ hashFiles('deno.lock') }} - name: Build documentation website run: "deno task build-docs --json" run: "deno task build-docs --base-url https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/ --json" - name: Upload artifact uses: actions/upload-pages-artifact@v3 with:
-
-
-
@@ -133,6 +133,7 @@ export async function run("logo-image", "doc-ext", "lang", "base-url", ], boolean: [ "help",
-
@@ -358,12 +359,25 @@ export async function run(}; } const baseURL = flags["base-url"] || configFile.output?.baseURL; try { if (baseURL) { new URL(baseURL, "macana://placeholder"); } } catch (error) { throw new Error( `baseURL is not valid URL nor path: ${String(error)}`, { cause: error }, ); } const pageBuilder = new DefaultThemeBuilder({ siteName, copyright, faviconSvg, faviconPng, siteLogo, baseURL, }); const documentTree = await treeBuilder.build({
-
@@ -465,6 +479,10 @@ ${title("Options")}:exist at the path. Use slash ("/") for path separator regardless of platform. Corresponding config key is ${p("output.path")} (${t("string")}). --base-url <PATH OR URL> URL or path to base at. Corresponding config key is ${p("output.baseURL")} (${t("string")}). --copyright <TEXT> Copyright text to display on the generated website. Corresponding config key is ${p("metadata.copyright")} (${t("string")}).
-
-
-
@@ -15,6 +15,8 @@ export interface MacanaConfig {path?: string; precompress?: boolean; baseURL?: string; }; metadata?: {
-
@@ -69,6 +71,7 @@ function configParser(configFilePath: string): parser.Parser<MacanaConfig> {}), output: parser.object({ path: fsPathParser, baseURL: parser.string({ nonEmpty: true, trim: true }), precompress: parser.boolean, }), metadata: parser.object({
-
-
-
@@ -20,6 +20,17 @@ Path needs to be relative and resolved from the config file.Path to the output directory. Path needs to be relative and resolved from the config file. ### `output.baseURL` - Type: `string` (URL or path) - CLI: `--base-url <URL OR PATH>` option - Example: `"/foo/"`, `"https://example.com/"` Base URL for the generated website. Path part needs to end with trailing slash: otherwise the last segment will be omitted. For example, link for the `Foo.md` under `--base-url /bar/baz` will look like `/bar/Foo/`. ### `output.precompress` - Type: `boolean`
-
-
-
@@ -26,7 +26,7 @@ updatedAt: 2024-05-26T18:50:00+09:00- [x] JSON/JSONC config for CLI - [x] Usage document for CLI - [x] Wikilink internal hash reference - [ ] Option to set base URL or path - [x] Option to set base URL or path ## v0.1.1
-
-
-
@@ -35,10 +35,10 @@ export interface BuildContext {copyright: string; /** * Resolves the given path as an absolute path from the document root to * relative path from the current document. * Returns full URL, absolute path or relative path from the current * document depends on a base URL. */ resolvePath(to: readonly string[]): readonly string[]; resolveURL(path: readonly string[]): string; /** * Copy file to the output directory.
-
-
-
@@ -39,7 +39,7 @@ function getUrl(url: string, node: Mdast.Node, context: BuildContext): string {context.copyFile(file); return context.resolvePath(file.path).join("/"); return context.resolveURL(file.path); } export interface EmbedHandlersParameters {
-
-
-
@@ -100,9 +100,9 @@ function getUrl(url: string, node: Mdast.Node, context: BuildContext): string {? "#" + document.content.getHash(fragments) : ""; const path = context.resolvePath([...document.path, ""]); const path = context.resolveURL([...document.path, ""]); return path.join("/") + hash; return path + hash; } export function linkHandlers(
-
-
-
@@ -76,26 +76,6 @@ function isJSONCanvas(return x.content.kind === "json_canvas"; } /** * @param from - **Directory** to resolve from. */ function toRelativePath( path: readonly string[], from: readonly string[], ): readonly string[] { return [ ...Array.from({ length: from.length }, () => ".."), ...path, ]; } function toRelativePathString( path: readonly string[], from: readonly string[], ): string { return toRelativePath(path, from).join("/"); } interface InnerBuildParameters { item: DocumentDirectory | Document;
-
@@ -142,6 +122,11 @@ export interface DefaultThemeBuilderConstructorParameters {ext: string; binary: Uint8Array; }; /** * URL or path to base at. */ baseURL?: URL | string; } /**
-
@@ -160,9 +145,10 @@ export class DefaultThemeBuilder implements PageBuilder {binary: Uint8Array; }; #siteName: string; #baseURL?: URL | string; constructor( { copyright, faviconSvg, faviconPng, siteLogo, siteName }: { copyright, faviconSvg, faviconPng, siteLogo, siteName, baseURL }: DefaultThemeBuilderConstructorParameters, ) { this.#copyright = copyright;
-
@@ -170,6 +156,7 @@ export class DefaultThemeBuilder implements PageBuilder {this.#faviconSvg = faviconSvg; this.#siteLogo = siteLogo; this.#siteName = siteName; this.#baseURL = baseURL; } async build(
-
@@ -248,7 +235,10 @@ export class DefaultThemeBuilder implements PageBuilder {} } const defaultPage = [...documentTree.defaultDocument.path, ""].join("/"); const defaultPage = this.#resolveURL([ ...documentTree.defaultDocument.path, "", ], []); const redirectHtml = toHtml(indexRedirect({ redirectTo: defaultPage })); await fileSystemWriter.write( ["index.html"],
-
@@ -320,7 +310,7 @@ export class DefaultThemeBuilder implements PageBuilder {return { ...node, file: toRelativePathString(file.path, context.document.path), file: context.resolveURL(file.path), }; }
-
@@ -398,6 +388,8 @@ export class DefaultThemeBuilder implements PageBuilder {{ item, tree, parentLanguage, pathPrefix = [], buildParameters, assets }: InnerBuildParameters, ): Promise<void> { const resolveURL = this.#resolveURL; const { fileSystemWriter } = buildParameters; if ("file" in item) {
-
@@ -410,9 +402,8 @@ export class DefaultThemeBuilder implements PageBuilder {assets, websiteTitle: this.#siteName, copyright: this.#copyright, resolvePath(to) { // This page builder transforms path to "Foo/Bar.md" to "Foo/Bar/(index.html)" return toRelativePath(to, item.path); resolveURL(to) { return resolveURL(to, item.path); }, copyFile(file) { writeTasks.push(
-
@@ -464,7 +455,7 @@ export class DefaultThemeBuilder implements PageBuilder {return { ...node, file: toRelativePathString(file.path, item.path), file: context.resolveURL(file.path), }; }
-
@@ -551,4 +542,27 @@ export class DefaultThemeBuilder implements PageBuilder {}) )); } #resolveURL = (to: readonly string[], from: readonly string[]): string => { if (!this.#baseURL) { return [ ...Array.from({ length: from.length }, () => ".."), ...to, ].join("/"); } if (this.#baseURL instanceof URL) { return new URL(to.join("/"), this.#baseURL).toString(); } const url = new URL( to.join("/"), new URL(this.#baseURL, "macana://placeholder"), ); if (url.protocol === "macana:") { return url.pathname; } return url.toString(); }; }
-
-
-
@@ -17,7 +17,7 @@ export interface TemplateProps {} export function template({ body, context, scripts = [] }: TemplateProps) { const { language, document, websiteTitle, assets, resolvePath } = context; const { language, document, websiteTitle, assets, resolveURL } = context; return ( <html lang={language}>
-
@@ -27,20 +27,20 @@ export function template({ body, context, scripts = [] }: TemplateProps) {<title>{document.metadata.title} - {websiteTitle}</title> <link rel="stylesheet" href={resolvePath(assets.globalCss).join("/")} href={resolveURL(assets.globalCss)} /> {assets.faviconSvg && ( <link rel="icon" type="image/svg+xml" href={resolvePath(assets.faviconSvg).join("/")} href={resolveURL(assets.faviconSvg)} /> )} {assets.faviconPng && ( <link rel="icon" type="image/png" href={resolvePath(assets.faviconPng).join("/")} href={resolveURL(assets.faviconPng)} /> )} </head>
-
-
-
@@ -170,7 +170,7 @@ interface NodeProps {function node({ currentPath, value, context }: NodeProps) { if ("file" in value) { const path = context.resolvePath([ const url = context.resolveURL([ ...value.path.map((segment) => encodeURIComponent(segment)), // For trailing slash "",
-
@@ -183,7 +183,7 @@ function node({ currentPath, value, context }: NodeProps) {<li lang={value.metadata.language ?? undefined} class={c.document}> <a className={c.link} href={path.join("/")} href={url} aria-current={isCurrent ? "page" : undefined} > {value.metadata.title}
-
-
-
@@ -279,7 +279,7 @@ export function layout({}: LayoutProps) { const { assets, resolvePath, resolveURL, documentTree: { defaultDocument }, websiteTitle, } = context;
-
@@ -302,14 +302,14 @@ export function layout({<header class={c.appbar}> <a class={c.homeLink} href={resolvePath([...defaultDocument.path, ""]).join("/")} href={resolveURL([...defaultDocument.path, ""])} title={defaultDocument.metadata.title} lang={defaultDocument.metadata.language} > {assets.siteLogo && ( <img class={c.logoImage} src={resolvePath(assets.siteLogo).join("/")} src={resolveURL(assets.siteLogo)} width={32} height={32} />
-