Skip to content

Commit

Permalink
Add config from aep repo (#16)
Browse files Browse the repository at this point in the history
* add repo link through config loader

* config
  • Loading branch information
rambleraptor authored Sep 21, 2024
1 parent 57d2a0b commit 967443a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
22 changes: 21 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import tailwind from "@astrojs/tailwind";
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"));


// https://astro.build/config
Expand All @@ -17,8 +18,27 @@ export default defineConfig({
'./src/tailwind.css',
],
social: {
github: 'https://github.com/withastro/starlight'
github: config.urls.repo,
},
// Google Analytics tag.
head: [
{
tag: 'script',
attrs: {
src: `<https://www.googletagmanager.com/gtag/js?id=${config.site.ga_tag}>`,
async: true,
},
},
{
tag: 'script',
content: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', ${config.site.ga_tag});
`,
},
],
sidebar: sidebar.concat(linter_sidebar)
}),
tailwind({
Expand Down
6 changes: 5 additions & 1 deletion scripts/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs';
import * as path from 'path';
import { load, dump } from "js-yaml";

import { glob } from 'glob';
import loadConfigFiles from './src/config';

interface AEP {
title: string;
Expand Down Expand Up @@ -450,6 +450,10 @@ function buildRedirects(aeps: AEP[]): object {
return Object.fromEntries(aeps.map((aep) => [`/${aep.id}`, `/${aep.slug}`]));
}

// Build config.
let config = loadConfigFiles("hero.yaml", "urls.yaml", "site.yaml");
writeSidebar(config, "config.json");

// Build out AEPs.
let aeps = await assembleAEPs();

Expand Down
51 changes: 51 additions & 0 deletions scripts/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import fs from 'fs';
import yaml from 'js-yaml';
import path from 'path';
import { z } from "zod";

const AEP_LOC = process.env.AEP_LOCATION!;

const Config = z.object({
hero: z.object({
buttons: z.array(z.object({
text: z.string(),
href: z.string(),
})),
shortcuts: z.array(z.object({
title: z.string(),
description: z.string(),
button: z.object({
text: z.string(),
href: z.string(),
}),
})),
}),
site: z.object({
ga_tag: z.string(),
}),
urls: z.object({
site: z.string(),
repo: z.string(),
}),
});

type Config = z.infer<typeof Config>;

function loadConfigFiles(...fileNames: string[]): Config {
const config = {};

fileNames.forEach((fileName) => {
try {
const filePath = path.join(AEP_LOC, "config", fileName);
const fileContents = fs.readFileSync(filePath, 'utf8');
const parsedYaml = yaml.load(fileContents);
config[fileName.replace('.yaml', '')] = parsedYaml;
} catch (error) {
console.error(`Error loading ${fileName}:`, error);
}
});

return Config.parse(config);
}

export default loadConfigFiles;

0 comments on commit 967443a

Please sign in to comment.