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

Automatically add .nojekyll file to support GitHub Pages #1693

Merged
merged 2 commits into from Sep 13, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions examples/basic/src/index.ts
@@ -0,0 +1,15 @@
export * from "./access";
export * from "./classes";
export * from "./default-export";
export * from "./enumerations";
export * from "./flattened";
export * from "./functions";
export * from "./generics";
export * from "./hidden";
export * from "./markdown";
export * from "./mixin";
export * from "./mod";
export * from "./mod2";
export * from "./modules";
export { default as SingleExportedClass } from "./single-export";
export * from "./weird-names";
3 changes: 2 additions & 1 deletion examples/basic/tsconfig.json
Expand Up @@ -5,7 +5,8 @@
"jsx": "react",
"experimentalDecorators": true,
"resolveJsonModule": true,
"rootDir": "."
"rootDir": ".",
"esModuleInterop": true
},
"include": ["."]
}
2 changes: 1 addition & 1 deletion src/lib/output/plugins/index.ts
@@ -1,5 +1,5 @@
export { AssetsPlugin } from "./AssetsPlugin";
export { JavascriptIndexPlugin } from "./JavascriptIndexPlugin";
export { MarkedLinksPlugin } from "./MarkedLinksPlugin";
export { MarkedPlugin as MarkedPlugin } from "../themes/MarkedPlugin";
export { MarkedPlugin } from "../themes/MarkedPlugin";
export { LegendPlugin } from "./LegendPlugin";
23 changes: 22 additions & 1 deletion src/lib/output/renderer.ts
Expand Up @@ -8,6 +8,7 @@
*/
import type * as ts from "typescript";
import * as fs from "fs";
import * as path from "path";

import type { Application } from "../application";
import type { Theme } from "./theme";
Expand Down Expand Up @@ -95,6 +96,10 @@ export class Renderer extends ChildableComponent<
@BindOption("gaSite")
gaSite!: string;

/** @internal */
@BindOption("githubPages")
githubPages!: boolean;

/** @internal */
@BindOption("hideGenerator")
hideGenerator!: boolean;
Expand Down Expand Up @@ -301,11 +306,27 @@ export class Renderer extends ChildableComponent<
fs.mkdirSync(directory, { recursive: true });
} catch (error) {
this.application.logger.error(
`Could not create output directory ${directory}`
`Could not create output directory ${directory}.`
);
return false;
}

if (this.githubPages) {
try {
const text =
"TypeDoc added this file to prevent GitHub Pages from " +
"using Jekyll. You can turn off this behavior by setting " +
"the `githubPages` option to false.";

fs.writeFileSync(path.join(directory, ".nojekyll"), text);
} catch (error) {
this.application.logger.warn(
"Could not create .nojekyll file."
);
return false;
}
}

return true;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/utils/options/declaration.ts
Expand Up @@ -86,6 +86,7 @@ export interface TypeDocOptionMap {
gitRemote: string;
gaID: string;
gaSite: string;
githubPages: boolean;
hideGenerator: boolean;
hideLegend: boolean;
cleanOutputDir: boolean;
Expand Down
6 changes: 6 additions & 0 deletions src/lib/utils/options/sources/typedoc.ts
Expand Up @@ -248,6 +248,12 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
help: "Set the site name for Google Analytics. Defaults to `auto`.",
defaultValue: "auto",
});
options.addDeclaration({
name: "githubPages",
help: "Generate a .nojekyll file to prevent 404 errors in GitHub Pages. Defaults to `true`.",
type: ParameterType.Boolean,
defaultValue: true,
});
options.addDeclaration({
name: "hideGenerator",
help: "Do not print the TypeDoc link at the end of the page.",
Expand Down