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

Generate non-chapter pages in Sitemap based on JSON config #1027

Merged
merged 3 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions src/templates/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@
<lastmod>2020-03-02</lastmod>
</url>

<url>
<loc>https://almanac.httparchive.org/en/2020/</loc>
<lastmod>2020-07-11</lastmod>
</url>

<url>
<loc>https://almanac.httparchive.org/en/accessibility-statement</loc>
<lastmod>2020-06-21</lastmod>
Expand Down Expand Up @@ -166,6 +171,11 @@
<lastmod>2020-06-21</lastmod>
</url>

<url>
<loc>https://almanac.httparchive.org/es/2020/</loc>
<lastmod>2020-07-11</lastmod>
</url>

<url>
<loc>https://almanac.httparchive.org/fr/2019/</loc>
<lastmod>2020-06-21</lastmod>
Expand Down Expand Up @@ -231,6 +241,11 @@
<lastmod>2020-05-05</lastmod>
</url>

<url>
<loc>https://almanac.httparchive.org/fr/2020/</loc>
<lastmod>2020-07-11</lastmod>
</url>

<url>
<loc>https://almanac.httparchive.org/ja/2019/</loc>
<lastmod>2020-06-21</lastmod>
Expand Down Expand Up @@ -351,6 +366,11 @@
<lastmod>2020-05-14</lastmod>
</url>

<url>
<loc>https://almanac.httparchive.org/ja/2020/</loc>
<lastmod>2020-07-11</lastmod>
</url>

<url>
<loc>https://almanac.httparchive.org/ja/accessibility-statement</loc>
<lastmod>2020-06-21</lastmod>
Expand Down
2 changes: 1 addition & 1 deletion src/tools/generate/generate_chapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const generate_chapters = async () => {
await generate_ebooks(ebook_chapters,configs);
await generate_js();

const sitemap_path = await generate_sitemap(sitemap);
const sitemap_path = await generate_sitemap(sitemap,sitemap_languages);
await size_of(sitemap_path);
};

Expand Down
22 changes: 13 additions & 9 deletions src/tools/generate/generate_sitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const static_pages = [
];
const ebook_path = "static/pdfs/web_almanac_";

const generate_sitemap = async (sitemap_chapters) => {
const generate_sitemap = async (sitemap_chapters,sitemap_languages) => {

const urls = await get_static_pages(sitemap_chapters);
const urls = await get_static_pages(sitemap_languages);

for (let sitemap_chapter of sitemap_chapters) {
let { language, year, chapter, metadata } = sitemap_chapter;
Expand All @@ -39,10 +39,15 @@ const generate_sitemap = async (sitemap_chapters) => {
return sitemap_path;
};

const get_static_pages = async (sitemap_chapters) => {
const get_static_pages = async (sitemap_languages) => {

// Get distinct languages and years
const languages_and_years = [...new Set(sitemap_chapters.map((x) => `${x.language}/${x.year}`))];
var languages_and_years = [];

for (const year in sitemap_languages) {
for (const languages in sitemap_languages[year]) {
languages_and_years.push(`${sitemap_languages[year][languages]}/${year}`);
}
}

// Get all of the static pages for each combination
const files = languages_and_years
Expand All @@ -64,10 +69,9 @@ const get_static_pages = async (sitemap_chapters) => {
}

// For ebooks find out if the PDF exists, get lastmod from template
const years = [...new Set(sitemap_chapters.map((x) => `${x.year}`))];
const languages = [...new Set(sitemap_chapters.map((x) => `${x.language}`))];
for (const year of years) {
for (const language of languages) {
for (const year in sitemap_languages) {
for (const languages in sitemap_languages[year]) {
const language = sitemap_languages[year][languages];
const ebook_pdf = ebook_path + year + '_' + language + '.pdf';
const ebook_html = 'templates/' + language + '/' + year + '/ebook.html';
if (fs.existsSync(ebook_pdf)) {
Expand Down