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

Sidebar changes #24

Merged
merged 2 commits into from
Sep 28, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { VitePluginRadar } from 'vite-plugin-radar';


let sidebar = JSON.parse(fs.readFileSync("generated/sidebar.json"));
let linter_sidebar = JSON.parse(fs.readFileSync("generated/linter_sidebar.json"));
let redirects = JSON.parse(fs.readFileSync("generated/redirects.json"));
let config = JSON.parse(fs.readFileSync("generated/config.json"));

Expand All @@ -28,8 +27,7 @@ export default defineConfig({
social: {
github: config.urls.repo,
},
// Google Analytics tag.
sidebar: sidebar.concat(linter_sidebar)
sidebar: sidebar
}),
tailwind({
applyBaseStyles: false,
Expand Down
78 changes: 44 additions & 34 deletions scripts/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { type AEP, type ConsolidatedLinterRule, type GroupFile, type LinterRule,
import { buildMarkdown, Markdown } from './src/markdown';
import { load, dump } from "js-yaml";

const AEP_LOC = process.env.AEP_LOCATION!;
const AEP_LINTER_LOC = process.env.AEP_LINTER_LOC!;
const AEP_LOC = process.env.AEP_LOCATION || "";
const AEP_LINTER_LOC = process.env.AEP_LINTER_LOC || "";

async function getFolders(dirPath: string): Promise<string[]> {
const entries = await fs.promises.readdir(dirPath, { withFileTypes: true });
Expand Down Expand Up @@ -272,48 +272,58 @@ function buildHomepage(): Markdown {
return markdown;
}

// Build config.
let config = loadConfigFiles("hero.yaml", "urls.yaml", "site.yaml");
writeSidebar(config, "config.json");
let sidebar: Sidebar = [];

// Build out AEPs.
let aeps = await assembleAEPs();
if(AEP_LOC != "") {
// Build config.
let config = loadConfigFiles("hero.yaml", "urls.yaml", "site.yaml");
writeSidebar(config, "config.json");

// Build sidebar.
let sidebar = buildSidebar(aeps, readGroupFile(AEP_LOC));
// Write assorted pages.
sidebar = await writePages(AEP_LOC, sidebar);

let full_aeps = buildFullAEPList(aeps);
writeSidebar(full_aeps, "full_aeps.json");
// Build out AEPs.
let aeps = await assembleAEPs();

// Build sidebar.
sidebar = buildSidebar(aeps, readGroupFile(AEP_LOC), sidebar);

// Write AEPs to files.
for (var aep of aeps) {
writeMarkdown(aep);
}
let full_aeps = buildFullAEPList(aeps);
writeSidebar(full_aeps, "full_aeps.json");

// Write assorted pages.
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")
// Write AEPs to files.
for (var aep of aeps) {
writeMarkdown(aep);
}

// Write site generator.
await writePage(".", "README.md", "src/content/docs/tooling/website/index.md", "")
writeSidebar(sidebar, "sidebar.json");
buildIndexPage(aeps);
writeSidebar(buildRedirects(aeps), "redirects.json");

// Write out linter rules.
let linter_rules = await assembleLinterRules();
let consolidated_rules = consolidateLinterRule(linter_rules);
for (var rule of consolidated_rules) {
writeRule(rule);
let homePage = buildHomepage();
fs.writeFileSync("src/content/docs/index.mdx", homePage.build());
} else {
console.warn("AEP repo is not found.")
}

var linter_sidebar = buildLinterSidebar(consolidated_rules);
addToSidebar(linter_sidebar, "Tooling", [{label: "Website", link: "tooling/website"}]);
writeSidebar(linter_sidebar, "linter_sidebar.json");
if (AEP_LINTER_LOC != "") {
// Write linter pages.
await writePage(AEP_LINTER_LOC, "README.md", "src/content/docs/tooling/linter/index.md", "Protobuf Linter")

// Write site generator.
await writePage(".", "README.md", "src/content/docs/tooling/website/index.md", "")

buildIndexPage(aeps);
writeSidebar(buildRedirects(aeps), "redirects.json");
// Write out linter rules.
let linter_rules = await assembleLinterRules();
let consolidated_rules = consolidateLinterRule(linter_rules);
for (var rule of consolidated_rules) {
writeRule(rule);
}

sidebar = buildLinterSidebar(consolidated_rules, sidebar)
sidebar = addToSidebar(sidebar, "Tooling", [{label: "Website", link: "tooling/website"}]);
} else {
console.warn("Proto linter repo is not found.")
}

let homePage = buildHomepage();
fs.writeFileSync("src/content/docs/index.mdx", homePage.build());
writeSidebar(sidebar, "sidebar.json");
19 changes: 11 additions & 8 deletions scripts/src/sidebar.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Sidebar, AEP, ConsolidatedLinterRule } from './types';

function buildLinterSidebar(rules: ConsolidatedLinterRule[]): Sidebar {
return [
function buildLinterSidebar(rules: ConsolidatedLinterRule[], sidebar: Sidebar): Sidebar {
let contents = [
{
label: 'Tooling',
items: [
Expand All @@ -19,28 +19,31 @@ function buildLinterSidebar(rules: ConsolidatedLinterRule[]): Sidebar {
]
}
];
return addToSidebar(sidebar, "Tooling", contents);
}

function buildSidebar(aeps: AEP[], groups: any): Sidebar {
let response = [{'label': 'Overview', 'items':[]}];

function buildSidebar(aeps: AEP[], groups: any, sidebar: Sidebar): Sidebar {
let response = [];
for (var group of groups.categories) {
response.push({
'label': group.title,
'items': aeps.filter((aep) => aep.category == group.code).sort((a1, a2) => a1.order > a2.order ? 1 : -1).map((aep) => ({label: `${aep.id}. ${aep.title}`, link: aep.slug}))
'items': aeps.filter((aep) => aep.category == group.code).sort((a1, a2) => a1.id > a2.id ? 1 : -1).map((aep) => ({label: `${aep.id}. ${aep.title}`, link: aep.slug}))
})
}
return response as Sidebar;

return addToSidebar(sidebar, "AEPs", response);
}

function addToSidebar(sidebar: Sidebar, label: string, items: string[]): Sidebar {
function addToSidebar(sidebar: Sidebar, label: string, items): 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;
}
} else {
sidebar.push({'label': label, items: items})
}
return sidebar;
}
Expand Down
Loading