Skip to content
This repository has been archived by the owner on Aug 17, 2024. It is now read-only.

Fix Trailing Slash Issue #254

Closed
wants to merge 1 commit into from
Closed
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 docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ module.exports = {
docs: {
sidebarPath: require.resolve("./sidebars.js"),
editUrl: "https://github.com/CodeYourFuture/Syllabus-V2/edit/master/",
routeBasePath: "/", // Set this value to '/'.
routeBasePath: "/",
},
theme: {
customCss: require.resolve("./src/css/custom.css"),
},
},
],
],
plugins: ["./sitePlugin"],
themeConfig: {
googleAnalytics: {
trackingID: "UA-159979458-2",
Expand Down
98 changes: 94 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.9.1",
"classnames": "^2.2.6",
"fs-extra": "^10.0.0",
"glob-promise": "^4.1.0",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-vertical-timeline-component": "^3.0.2"
Expand Down
51 changes: 51 additions & 0 deletions sitePlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

const glob = require("glob-promise");
const path = require("path");
const fs = require("fs-extra");

// quick fix for GH pages trailing slash issues
// /myDoc/index.html => /myDoc.html
async function generateSimpleHtmlFiles(outDir) {
console.log("generateSimpleHtmlFiles", outDir);

const pattern = path.join(outDir, "/**/index.html");
// console.log('pattern', pattern);

const filePaths = (await glob(pattern)).filter((filePath) => {
return filePath !== path.join(outDir, "/index.html");
});

// console.log('filePaths', filePaths);

await Promise.all(
filePaths.map(async (filePath) => {
if ((await fs.stat(filePath)).isDirectory()) {
return;
}
// console.log(file);
const filePathCopy = `${path.dirname(filePath)}.html`;
if (await fs.pathExists(filePathCopy)) {
// console.log(`Skipping ${filePathCopy}`);
} else {
await fs.copyFile(filePath, filePathCopy);
// console.log(`Created ${filePathCopy}`);
}
})
);
}

module.exports = function () {
console.log("site plugin");
return {
plugin: "site-plugin",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could change this to be a bit more specific? I feel like it might trip us up in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the file name too.

async postBuild(props) {
await generateSimpleHtmlFiles(props.outDir);
},
};
};