-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10246 from linode/release-v1.114.0
Release v1.114.0 - release → staging
- Loading branch information
Showing
322 changed files
with
9,209 additions
and
6,919 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,89 @@ | ||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
import { readdirSync } from "fs"; | ||
import { join } from "path"; | ||
import { DOCS_SRC_DIR } from "../config"; | ||
|
||
const DEVELOPMENT_GUIDE_PATH = "./docs/development-guide"; | ||
type LinkItem = { text: string; link: string }; | ||
|
||
interface MarkdownInfo { | ||
text: string; | ||
link: string; | ||
type SidebarItem = | ||
| { | ||
text: string; | ||
collapsed?: boolean; | ||
items: SidebarItem[] | LinkItem[]; | ||
} | ||
| LinkItem; | ||
|
||
const exclude = [ | ||
"cache", | ||
"public", | ||
"PULL_REQUEST_TEMPLATE.md", | ||
".vitepress", | ||
"index.md", | ||
]; | ||
|
||
const replacements = [ | ||
["-", " "], | ||
["_", " "], | ||
[".md", ""], | ||
]; | ||
|
||
function isPathIgnored(path: string) { | ||
for (const item of exclude) { | ||
if (path.includes(item)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
function capitalize(s: string) { | ||
return ( | ||
s.substring(0, 1).toUpperCase() + s.substring(1, s.length).toLowerCase() | ||
); | ||
} | ||
|
||
/** | ||
* Aggregates the pages in the development-guide and populates the left sidebar. | ||
* Given a file name, this function returns a formatted title. | ||
*/ | ||
const scanDirectory = (directoryPath: string): MarkdownInfo[] => { | ||
const markdownFiles = fs | ||
.readdirSync(directoryPath) | ||
.filter((file) => file.endsWith(".md")); | ||
const markdownInfoArray: MarkdownInfo[] = []; | ||
function formatSidebarItemText(fileName: string) { | ||
// removes -, _, and .md from files names to generate the title | ||
for (const [from, to] of replacements) { | ||
fileName = fileName.replaceAll(from, to); | ||
} | ||
// Removes any number prefix. This allows us to order things by putting numbers in file names. | ||
fileName = fileName.replace(/^[0-9]*/, ""); | ||
// Capitalizes each word in the file name | ||
fileName = fileName.split(" ").map(capitalize).join(" "); | ||
return fileName; | ||
} | ||
|
||
markdownFiles.forEach((file) => { | ||
const filePath = path.join(directoryPath, file); | ||
const fileContent = fs.readFileSync(filePath, "utf-8"); | ||
/** | ||
* Generates a VitePress sidebar by recursively traversing the given directory. | ||
*/ | ||
export function generateSidebar(dir: string) { | ||
const files = readdirSync(dir, { withFileTypes: true }); | ||
|
||
const titleMatch = fileContent.match(/^#\s+(.*)/m); | ||
const title = titleMatch ? titleMatch[1] : "Untitled"; | ||
const sidebar: SidebarItem[] = []; | ||
|
||
const markdownInfo: MarkdownInfo = { | ||
text: title, | ||
link: `/development-guide/${file}`, | ||
}; | ||
for (const file of files) { | ||
const filepath = join(dir, file.name); | ||
|
||
markdownInfoArray.push(markdownInfo); | ||
}); | ||
if (isPathIgnored(filepath)) { | ||
continue; | ||
} | ||
|
||
return markdownInfoArray; | ||
}; | ||
if (file.isDirectory()) { | ||
sidebar.push({ | ||
text: formatSidebarItemText(file.name), | ||
collapsed: false, | ||
items: generateSidebar(filepath), | ||
}); | ||
} else { | ||
sidebar.push({ | ||
text: formatSidebarItemText(file.name), | ||
link: filepath.split(DOCS_SRC_DIR)[1], | ||
}); | ||
} | ||
} | ||
|
||
export const guides = scanDirectory(DEVELOPMENT_GUIDE_PATH); | ||
return sidebar; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["ESNext"], | ||
"module": "ESNext", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.