Skip to content

Commit

Permalink
feat: setup sidebar labels and position
Browse files Browse the repository at this point in the history
  • Loading branch information
kittybest committed Jan 19, 2024
1 parent 77a424d commit b1d0bcc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
9 changes: 9 additions & 0 deletions website/src/scripts/setupSolidityDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ function updateHeadings(dir: string) {
});
}

function insertIndexPage(dir: string) {
fs.writeFileSync(
`${dir}/index.md`,
`---\ntitle: Solidity Docs\ndescription: Solidity Docs\nsidebar_label: Solidity Docs\n---\n`,
);
}

// copy over the directory
copyDirectory(sourceDir, solidityDocDir);
// update the headings
updateHeadings(solidityDocDir);
// insert index page
insertIndexPage(solidityDocDir);
32 changes: 26 additions & 6 deletions website/src/scripts/setupTypedoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,23 @@ import { copyDirectory } from "./utils";
const TYPEDOC_DIR = path.resolve(__dirname, "../../typedoc");

/**
* The Typedoc tool automatically generates related documentation links in each file. The link for the introduction of MACI is initially set to `README.md` of the entire project, but this should be changed to `introduction.md`. Simultaneously, references to `modules.md` should be updated to `index.md` since it is slated to be renamed as Typedoc's homepage.
* A function that forces the first letter to be capital,
* while the rest of the string must be lower case.
* @param str - the string being transformed
*/
function fitFormat(str: string) {
return str[0].toUpperCase() + str.slice(1, str.length).toLowerCase();
}

/**
* The Typedoc tool automatically generates related documentation links in each file.
* The link for the introduction of MACI is initially set to `README.md` of the entire project,
* but this should be changed to `introduction.md`.
* Simultaneously, references to `modules.md` should be updated to `index.md`
* since it is slated to be renamed as Typedoc's homepage.
* @param dirName - the name of the typedoc directory
*/
function updateMentionFiles(dirName: string) {
function updateMentionFiles(dirName: string, position: number) {
const dir = path.join(TYPEDOC_DIR, dirName);
const files = fs.readdirSync(dir);
files.forEach((file) => {
Expand All @@ -19,6 +32,12 @@ function updateMentionFiles(dirName: string) {
content = content.replaceAll("../modules.md", "../index.md");
fs.writeFileSync(filename, content);
});

const name = fitFormat(dirName);
fs.writeFileSync(
`${dir}/index.md`,
`---\ntitle: ${name}\ndescription: ${name}\nsidebar_label: ${name}\nsidebar_position: ${position}\n---\n`,
);
}

// Remove the README.md file if exists
Expand All @@ -27,19 +46,20 @@ if (fs.existsSync(readmeFile)) {
fs.unlinkSync(readmeFile);
}

// Rename modules.md to index.md, and change the README.md mention to ../introduction.md
// Rename modules.md to index.md, and change the README.md mentions to ../introduction.md
const modulesFile = path.join(TYPEDOC_DIR, "modules.md");
if (fs.existsSync(modulesFile)) {
let content = fs.readFileSync(modulesFile, "utf8");
content = content.replaceAll("README.md", "../introduction.md");
content = `---\ntitle: Typedoc\ndescription: Typedoc\nsidebar_label: Typedoc\n---\n\n${content}`;
fs.writeFileSync(modulesFile, content);
fs.renameSync(modulesFile, path.join(TYPEDOC_DIR, "index.md"));
}

// Change all ../README.md mention to ../../introduction.md, and change all ../modeuls.md mention to ../index.md
updateMentionFiles("classes");
updateMentionFiles("interfaces");
updateMentionFiles("modules");
updateMentionFiles("modules", 1);
updateMentionFiles("classes", 2);
updateMentionFiles("interfaces", 3);

// find the target moving directory
const versionFile = path.resolve(__dirname, "../../versions.json");
Expand Down

0 comments on commit b1d0bcc

Please sign in to comment.