From 881d5991f5a0a9f09ee18a8970c8489f39b18417 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Sat, 21 Sep 2024 17:29:44 -0400 Subject: [PATCH 1/6] wip --- scripts/generate.ts | 33 ++++++++++++++++++++------------- scripts/src/sidebar.ts | 18 +++++++++++++++--- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/scripts/generate.ts b/scripts/generate.ts index 7d01005..d79c810 100644 --- a/scripts/generate.ts +++ b/scripts/generate.ts @@ -3,9 +3,9 @@ import * as path from 'path'; import { load, dump } from "js-yaml"; import loadConfigFiles from './src/config'; -import { buildSidebar, buildLinterSidebar } from './src/sidebar'; -import type { AEP, ConsolidatedLinterRule, GroupFile, LinterRule, Markdown } from './src/types'; -import { buildMarkdown } from './src/markdown'; +import { buildSidebar, buildLinterSidebar, addToSidebar } from './src/sidebar'; +import { type AEP, type ConsolidatedLinterRule, type GroupFile, type LinterRule, type Sidebar } from './src/types'; +import { buildMarkdown, Markdown } from './src/markdown'; const AEP_LOC = process.env.AEP_LOCATION!; const AEP_LINTER_LOC = process.env.AEP_LINTER_LOC!; @@ -30,28 +30,31 @@ async function getLinterRules(dirPath: string): Promise { return folders; } -async function writePage(dirPath: string, filename: string) { - let contents = fs.readFileSync(path.join(dirPath, filename), 'utf-8') +async function writePage(dirPath: string, filename: string, outputPath: string, title: string) { + let contents = new Markdown(fs.readFileSync(path.join(dirPath, filename), 'utf-8')); let frontmatter = { - 'title': getTitle(contents.toString()) + 'title': title ?? getTitle(contents.contents) } let final = `--- ${dump(frontmatter)} --- -${contents}` - fs.writeFileSync(path.join("src/content/docs", filename), final, { flag: 'w' }); +${contents.removeTitle().contents}` + fs.writeFileSync(outputPath, final, { flag: 'w' }); } -async function writePages(dirPath: string) { +async function writePages(dirPath: string, sidebar: Sidebar): Promise { const entries = await fs.promises.readdir(path.join(dirPath, "pages/general/"), { withFileTypes: true }); let files = entries .filter(entry => entry.isFile() && entry.name.endsWith('.md')) for (var file of files) { - writePage(path.join(dirPath, "pages/general"), file.name); + writePage(path.join(dirPath, "pages/general"), file.name, path.join("src/content/docs", file.name)); + addToSidebar(sidebar, "Overview", [file.name.replace('.md', '.mdx')]) } - writePage(dirPath, "CONTRIBUTING.md"); + writePage(dirPath, "CONTRIBUTING.md", path.join("src/content/docs", "contributing.md")); + addToSidebar(sidebar, "Overview", ["contributing"]); + return sidebar; } function readAEP(dirPath: string): string[] { @@ -248,7 +251,6 @@ let aeps = await assembleAEPs(); // Build sidebar. let sidebar = buildSidebar(aeps, readGroupFile(AEP_LOC)); -writeSidebar(sidebar, "sidebar.json"); let full_aeps = buildFullAEPList(aeps); writeSidebar(full_aeps, "full_aeps.json"); @@ -260,7 +262,12 @@ for (var aep of aeps) { } // Write assorted pages. -writePages(AEP_LOC); +sidebar = await writePages(AEP_LOC, sidebar); + +// Write linter pages. +await writePage(AEP_LINTER_LOC, "README.md", "src/content/docs/tooling/linter/index.md", "Protobuf Linter") + +writeSidebar(sidebar, "sidebar.json"); // Write out linter rules. let linter_rules = await assembleLinterRules(); diff --git a/scripts/src/sidebar.ts b/scripts/src/sidebar.ts index 23568b7..764cdc0 100644 --- a/scripts/src/sidebar.ts +++ b/scripts/src/sidebar.ts @@ -6,7 +6,7 @@ function buildLinterSidebar(rules: ConsolidatedLinterRule[]): Sidebar { label: 'Tooling', items: [ { - 'label': 'Linter', + 'label': 'Protobuf Linter', 'items': [ 'tooling/linter', { @@ -22,7 +22,7 @@ function buildLinterSidebar(rules: ConsolidatedLinterRule[]): Sidebar { } function buildSidebar(aeps: AEP[], groups: any): Sidebar { - let response = []; + let response = [{'label': 'Overview', 'items':[]}]; for (var group of groups.categories) { response.push({ @@ -33,4 +33,16 @@ function buildSidebar(aeps: AEP[], groups: any): Sidebar { return response as Sidebar; } -export { buildSidebar, buildLinterSidebar }; \ No newline at end of file +function addToSidebar(sidebar: Sidebar, label: string, items: string[]): Sidebar { + const targetGroupIndex = sidebar.findIndex(group => group.label === label); + if (targetGroupIndex != -1) { + if (Array.isArray(sidebar[targetGroupIndex].items)) { + sidebar[targetGroupIndex].items.push(...items); + } else { + sidebar[targetGroupIndex].items = items; + } + } + return sidebar; +} + +export { buildSidebar, buildLinterSidebar, addToSidebar }; \ No newline at end of file From c758d24e5f6ad74b779ce2fbe4b7987a50fa13f1 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Sun, 22 Sep 2024 14:10:53 -0400 Subject: [PATCH 2/6] generating linter overview based on linter readme --- src/content/docs/tooling/linter/index.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 src/content/docs/tooling/linter/index.md diff --git a/src/content/docs/tooling/linter/index.md b/src/content/docs/tooling/linter/index.md deleted file mode 100644 index 0568b1b..0000000 --- a/src/content/docs/tooling/linter/index.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -title: Linter ---- - -We have a linter! From c1c3b69e616180afe3bbdbaf67057ef5f1d1cfb7 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Sun, 22 Sep 2024 14:15:08 -0400 Subject: [PATCH 3/6] build ci --- .github/workflows/build.yaml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..e94bef8 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,36 @@ +--- +name: build +on: + pull_request: + branches: + - main + +# Recommended by https://github.com/JamesIves/github-pages-deploy-action +permissions: + contents: read + pages: write + id-token: write +jobs: + build: + runs-on: ubuntu-latest + container: node:20 + steps: + - uses: actions/checkout@v3 + - name: Clone aep.dev + uses: actions/checkout@v3 + with: + repository: aep-dev/aep.dev + path: './aep-dev' + - name: Clone Proto linter + uses: actions/checkout@v3 + with: + repository: aep-dev/api-linter + path: './api-linter' + - name: Create rules folder + run: mkdir src/content/docs/tooling/linter/rules + - name: Install all dependencies. + run: npm install + - name: Generate all static pages. + run: AEP_LOCATION=./aep-dev AEP_LINTER_LOC=./api-linter npm run generate + - name: Install, build, and upload your site output + uses: withastro/action@v2 From c1c7d09bab9f700a1bb52a3e26dbe9163890d332 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Sun, 22 Sep 2024 14:17:15 -0400 Subject: [PATCH 4/6] wip --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index e94bef8..0eaefe3 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -27,7 +27,7 @@ jobs: repository: aep-dev/api-linter path: './api-linter' - name: Create rules folder - run: mkdir src/content/docs/tooling/linter/rules + run: ls && mkdir src/content/docs/tooling/linter/rules - name: Install all dependencies. run: npm install - name: Generate all static pages. From e504da564c604e3fe844d05b204dbf40baf54c22 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Sun, 22 Sep 2024 14:17:34 -0400 Subject: [PATCH 5/6] wip --- scripts/generate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/generate.ts b/scripts/generate.ts index d79c810..155212d 100644 --- a/scripts/generate.ts +++ b/scripts/generate.ts @@ -50,7 +50,7 @@ async function writePages(dirPath: string, sidebar: Sidebar): Promise { for (var file of files) { writePage(path.join(dirPath, "pages/general"), file.name, path.join("src/content/docs", file.name)); - addToSidebar(sidebar, "Overview", [file.name.replace('.md', '.mdx')]) + addToSidebar(sidebar, "Overview", [file.name.replace('.md', '')]) } writePage(dirPath, "CONTRIBUTING.md", path.join("src/content/docs", "contributing.md")); addToSidebar(sidebar, "Overview", ["contributing"]); From c7bc29e7ceb87597722157ea7cf552c116d44132 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Sun, 22 Sep 2024 14:19:35 -0400 Subject: [PATCH 6/6] ci fix --- .github/workflows/build.yaml | 2 +- .github/workflows/publish.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 0eaefe3..bff8ebe 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -27,7 +27,7 @@ jobs: repository: aep-dev/api-linter path: './api-linter' - name: Create rules folder - run: ls && mkdir src/content/docs/tooling/linter/rules + run: mkdir -p src/content/docs/tooling/linter/rules - name: Install all dependencies. run: npm install - name: Generate all static pages. diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 2fb0763..5a8366b 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -29,7 +29,7 @@ jobs: repository: aep-dev/api-linter path: './api-linter' - name: Create rules folder - run: mkdir src/content/docs/tooling/linter/rules + run: mkdir -p src/content/docs/tooling/linter/rules - name: Install all dependencies. run: npm install - name: Generate all static pages.