Skip to content

Commit

Permalink
update-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
encse committed Dec 12, 2024
1 parent 125b5f1 commit 952d011
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/update-docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Update Docs

on:
push:
branches:
- master

jobs:
update-docs:
runs-on: ubuntu-latest

permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16' # Update based on your project's requirements

- name: Build
run: |
cd docs;
npm install
cd ..
ls -la
node docs/build.js
- name: Deploy to Docs Branch
run: |
# Configure Git
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# Preserve built files
mv build ..
# Switch to the docs branch
git checkout --orphan docs
git rm -rf . || true
cp -r ../build/* .
rm -rf ../build
# Commit and push changes
git add .
git commit -m "Update docs on $(date)"
git push --force origin docs
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ bin
obj
aoc-crypt.key
docs/node_modules
build
13 changes: 11 additions & 2 deletions docs/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function generateDayPicker(year, day, yearToDays) {
return res;
}
const template = loadTemplate('docs/template.html');

const redirectTemplate = loadTemplate('docs/redirect_template.html')

const yearToDays = {};
for (const { year, day } of findReadmes('.')) {
Expand All @@ -123,10 +123,18 @@ for(const year of Object.keys(yearToDays)){
yearToDays[year] = yearToDays[year].sort((a,b) => a-b);
}


console.log(yearToDays);
const lastYear = Math.max(...Object.keys(yearToDays))
const lastDay = Math.max(...yearToDays[lastYear]);

copyDirectory('docs/static', 'build');

const filledRedirectTemplate = fillTemplate(redirectTemplate, {
'default-page-url': `https://aoc.csokavar.hu/${lastYear}/${lastDay}/`,
});

fs.writeFileSync(path.join('build', 'index.html'), filledRedirectTemplate);

// Iterate over readme.md files and print filled templates
for (const { year, day, name, notes, code, illustration } of findReadmes('.')) {
const filledHtml = fillTemplate(template, {
Expand All @@ -143,3 +151,4 @@ for (const { year, day, name, notes, code, illustration } of findReadmes('.')) {
fs.writeFileSync(path.join(dst, 'index.html'), filledHtml);
fs.copyFileSync(illustration, path.join(dst, 'illustration.jpeg'));
}

4 changes: 3 additions & 1 deletion docs/static/index.html → docs/redirect_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
const url = new URL(window.location.href);
if (url.search.match(/^\?(\d{4})\/\d{1,2}/)) {
window.location = url.search.substring(1);
}
} else {
window.location = '{{default-page-url}}';
}
</script>

0 comments on commit 952d011

Please sign in to comment.