Skip to content

Commit 9f9d01c

Browse files
committed
change url structure
1 parent d07d1be commit 9f9d01c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

docs/build.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ function copyDirectory(src, dest) {
8080
};
8181

8282

83+
function linkToDay(year, day) {
84+
return `/${year}/day/${day}`;
85+
}
86+
8387
function loadTemplate(templatePath) {
8488
return fs.readFileSync(templatePath, 'utf8');
8589
}
@@ -93,7 +97,7 @@ function generateYearPicker(year, day, yearToDays) {
9397
let options = '';
9498
for (let y of Object.keys(yearToDays).sort()){
9599
let lastDay = yearToDays[y][yearToDays[y].length-1];
96-
let target = `/${y}/${lastDay}/`
100+
let target = linkToDay(y, lastDay);
97101
options += `<a href="${target}">${y}</a>`
98102
}
99103

@@ -108,7 +112,7 @@ function generateYearPicker(year, day, yearToDays) {
108112
function generateDayPicker(year, day, yearToDays) {
109113
let res = '';
110114
for (i = 1; i <= yearToDays[year].length; i++) {
111-
const link = `<a href="/${year}/${i}">${i.toString().padStart(2, '0')}</a>`;
115+
const link = `<a href="${linkToDay(year, i)}">${i.toString().padStart(2, '0')}</a>`;
112116
res += i == day ? `<span class="current">${link}</span>` : `<span>${link}</span>`;
113117
}
114118
return res;
@@ -134,7 +138,7 @@ const lastDay = Math.max(...yearToDays[lastYear]);
134138
copyDirectory('docs/static', 'build');
135139

136140
const filledRedirectTemplate = fillTemplate(redirectTemplate, {
137-
'default-page': `/${lastYear}/${lastDay}/`,
141+
'default-page': linkToDay(lastYear, lastDay),
138142
});
139143

140144
fs.writeFileSync(path.join('build', 'index.html'), filledRedirectTemplate);
@@ -143,7 +147,7 @@ const currentYear = new Date().getFullYear();
143147
// Iterate over readme.md files and print filled templates
144148
for (const { year, day, name, notes, code, illustration } of findReadmes('.')) {
145149
const filledHtml = fillTemplate(template, {
146-
url: `https://aoc.csokavar.hu/${year}/${day}/`,
150+
url: `https://aoc.csokavar.hu/${linkToDay(year, day)}`,
147151
'problem-id': `${year}/${day}`,
148152
'problem-name': `${name}`,
149153
'year-picker': generateYearPicker(year,day, yearToDays),
@@ -152,7 +156,7 @@ for (const { year, day, name, notes, code, illustration } of findReadmes('.')) {
152156
notes,
153157
code,
154158
});
155-
const dst = `build/${year}/${day}`;
159+
const dst = `build/${year}/day/${day}`;
156160
fs.mkdirSync(dst, { recursive: true });
157161
fs.writeFileSync(path.join(dst, 'index.html'), filledHtml);
158162
fs.copyFileSync(illustration, path.join(dst, 'illustration.jpeg'));

docs/redirect_template.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<script>
44
const url = new URL(window.location.href);
55
if (url.search.match(/^\?(\d{4})\/\d{1,2}/)) {
6-
window.location = url.search.substring(1);
6+
let m = url.search.match(/^\?(\d{4})\/(\d{1,2})/);
7+
window.location = m[1] + "/day/"+m[2];
78
} else {
89
window.location = '{{default-page}}';
910
}

0 commit comments

Comments
 (0)