Skip to content

Commit 6541a2e

Browse files
committed
update-docs
1 parent 125b5f1 commit 6541a2e

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

.github/workflows/update-docs.yaml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Update Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
update-docs:
10+
runs-on: ubuntu-latest
11+
12+
permissions:
13+
# Give the default GITHUB_TOKEN write permission to commit and push the
14+
# added or changed files to the repository.
15+
contents: write
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v3
20+
21+
- name: Set up Node.js
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version: '16' # Update based on your project's requirements
25+
26+
- name: Build
27+
run: |
28+
cd docs;
29+
npm install
30+
cd ..
31+
ls -la
32+
node docs/build.js
33+
34+
- name: Deploy to Docs Branch
35+
run: |
36+
# Configure Git
37+
git config --global user.name "github-actions[bot]"
38+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
39+
40+
# Preserve built files
41+
mv build ..
42+
43+
# Switch to the docs branch
44+
git checkout docs
45+
git rm -rf . || true
46+
cp -r ../build/* .
47+
rm -rf ../build
48+
49+
# Commit and push changes
50+
git add .
51+
git commit -m "Update docs on $(date)"
52+
git push --force origin docs

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ bin
22
obj
33
aoc-crypt.key
44
docs/node_modules
5+
build

docs/build.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function* findReadmes(dir) {
1616
const day = parseInt(match[2], 10);
1717

1818
// Check the directory for a readme.md file
19-
const readmePath = path.join(fullPath, 'readme.md');
19+
const readmePath = path.join(fullPath, 'README.md');
2020
const solutionPath = path.join(fullPath, 'Solution.cs');
2121
const illustrationPath = path.join(fullPath, 'illustration.jpeg');
2222
if (fs.existsSync(readmePath) && fs.existsSync(solutionPath)) {
@@ -109,7 +109,7 @@ function generateDayPicker(year, day, yearToDays) {
109109
return res;
110110
}
111111
const template = loadTemplate('docs/template.html');
112-
112+
const redirectTemplate = loadTemplate('docs/redirect_template.html')
113113

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

126-
126+
console.log(yearToDays);
127+
const lastYear = Math.max(...Object.keys(yearToDays))
128+
const lastDay = Math.max(...yearToDays[lastYear]);
127129

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

132+
const filledRedirectTemplate = fillTemplate(redirectTemplate, {
133+
'default-page-url': `https://aoc.csokavar.hu/${lastYear}/${lastDay}/`,
134+
});
135+
136+
fs.writeFileSync(path.join('build', 'index.html'), filledRedirectTemplate);
137+
130138
// Iterate over readme.md files and print filled templates
131139
for (const { year, day, name, notes, code, illustration } of findReadmes('.')) {
132140
const filledHtml = fillTemplate(template, {
@@ -143,3 +151,4 @@ for (const { year, day, name, notes, code, illustration } of findReadmes('.')) {
143151
fs.writeFileSync(path.join(dst, 'index.html'), filledHtml);
144152
fs.copyFileSync(illustration, path.join(dst, 'illustration.jpeg'));
145153
}
154+

docs/static/index.html renamed to docs/redirect_template.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
const url = new URL(window.location.href);
55
if (url.search.match(/^\?(\d{4})\/\d{1,2}/)) {
66
window.location = url.search.substring(1);
7-
}
7+
} else {
8+
window.location = '{{default-page-url}}';
9+
}
810
</script>

0 commit comments

Comments
 (0)