Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support an option to add .html suffixes to the generated sites #13

Merged
merged 3 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion explorer/rdfconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"favicon.ico": "favicon.ico",
"robots.txt": "robots.txt"
},
"outDir": "public"
"outDir": "public",
"cleanUrls": true
}
}
11 changes: 6 additions & 5 deletions packages/cli/src/commands/make-site.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Website implements RenderContext {
readonly outputs: Record<string, string> = {};
readonly rootClasses: ReadonlySet<string> | null;

constructor(readonly title: string, readonly baseURL: string, rootClasses?: Iterable<string>) {
constructor(readonly title: string, readonly baseURL: string, readonly cleanUrls: boolean, rootClasses?: Iterable<string>) {
this.graph = Graph.from(this.dataset);
this.schema = Schema.decompile(this.dataset, this.graph);
this.prefixes = new PrefixTable(this.namespaces);
Expand Down Expand Up @@ -112,7 +112,7 @@ class Website implements RenderContext {
for (const term of terms) {
const prefixedName = this.prefixes.lookup(term.value);
if (prefixedName) {
this.outputs[term.value] = path.join(prefixedName.prefixLabel, prefixedName.localName);
this.outputs[term.value] = path.join(prefixedName.prefixLabel, prefixedName.localName) + (this.cleanUrls ? "" : ".html");
}
else {
const string = term.value;
Expand All @@ -122,7 +122,7 @@ class Website implements RenderContext {
hash = ((hash << 5) - hash) + char;
hash = hash & hash;
}
this.outputs[term.value] = (hash & ((1 << 31) - 1)).toString().padStart(10, "0");
this.outputs[term.value] = (hash & ((1 << 31) - 1)).toString().padStart(10, "0") + (this.cleanUrls ? "" : ".html");
}
}
}
Expand Down Expand Up @@ -221,7 +221,8 @@ export default function main(options: Options): void {
const project = new Project(options.project);
const icons = project.json.siteOptions?.icons || [];
const assets = project.json.siteOptions?.assets || {};
const context = new Website(project.json.siteOptions?.title || DEFAULT_TITLE, new URL(options.base || project.json.siteOptions?.baseURL || DEFAULT_BASE, DEFAULT_BASE).href, project.json.siteOptions?.roots);

const context = new Website(project.json.siteOptions?.title || DEFAULT_TITLE, new URL(options.base || project.json.siteOptions?.baseURL || DEFAULT_BASE, DEFAULT_BASE).href, !!project.json.siteOptions?.cleanUrls, project.json.siteOptions?.roots);
const site = new Workspace(project.package.resolve(options.output || project.json.siteOptions?.outDir || "public"));

context.beforecompile();
Expand Down Expand Up @@ -262,6 +263,6 @@ export default function main(options: Options): void {
site.write(ERROR_FILE_NAME, Buffer.from("<!DOCTYPE html>\n" + renderHTML(render404(context, links, scripts, navigation))));

for (const iri in context.outputs) {
site.write(context.outputs[iri] + ".html", Buffer.from("<!DOCTYPE html>\n" + renderHTML(renderPage(iri, context, links, scripts, navigation))));
site.write(context.outputs[iri] + (context.cleanUrls ? ".html" : ""), Buffer.from("<!DOCTYPE html>\n" + renderHTML(renderPage(iri, context, links, scripts, navigation))));
}
}
4 changes: 3 additions & 1 deletion packages/cli/src/model/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface SiteConfig {
baseURL?: string;
outDir?: string;
roots?: Array<string>;
cleanUrls?: boolean;
}

export namespace SiteConfig {
Expand All @@ -43,7 +44,8 @@ export namespace SiteConfig {
&& (Is.undefined(candidate.assets) || Is.objectLiteral(candidate.assets))
&& (Is.undefined(candidate.baseURL) || Is.string(candidate.baseURL))
&& (Is.undefined(candidate.outDir) || Is.string(candidate.outDir))
&& (Is.undefined(candidate.roots) || Is.typedArray(candidate.roots, Is.string));
&& (Is.undefined(candidate.roots) || Is.typedArray(candidate.roots, Is.string))
&& (Is.undefined(candidate.cleanUrls) || Is.boolean(candidate.cleanUrls));
}
}

Expand Down