add date index
This commit is contained in:
parent
72f964373e
commit
bc1cea780a
49
main.ts
49
main.ts
@ -1,5 +1,8 @@
|
|||||||
import { DOMParser } from "jsr:@b-fuze/deno-dom";
|
import { DOMParser } from "jsr:@b-fuze/deno-dom";
|
||||||
|
|
||||||
|
const ARTICLES_ID_MIN = 87;
|
||||||
|
const ARTICLES_ID_MAX = 88;
|
||||||
|
|
||||||
const downloadDate = new Date();
|
const downloadDate = new Date();
|
||||||
|
|
||||||
type ArticleInfo = {
|
type ArticleInfo = {
|
||||||
@ -132,6 +135,42 @@ function renderIndex(articles: ArticleInfo[]): string {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const datesTemplate = await Deno.readTextFile("templates/dates.html");
|
||||||
|
|
||||||
|
function renderDateIndex(articles: ArticleInfo[]): string {
|
||||||
|
return datesTemplate
|
||||||
|
.slice()
|
||||||
|
.replaceAll("$downloadDate", downloadDate.toUTCString())
|
||||||
|
.replaceAll(
|
||||||
|
"$articleEntriesByDate",
|
||||||
|
articles
|
||||||
|
.toSorted((a, b) =>
|
||||||
|
new Date(a.dateAdded).getTime() -
|
||||||
|
new Date(b.dateAdded).getTime()
|
||||||
|
)
|
||||||
|
.map((article) => `
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<a href="article-${article.id}.html">
|
||||||
|
${article.title}
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>${article.author}</td>
|
||||||
|
<td class="article-date">${
|
||||||
|
new Date(article.dateAdded).toUTCString()
|
||||||
|
}</td>
|
||||||
|
<td>${(
|
||||||
|
article.tags.map((tag) => `
|
||||||
|
<a href="categories.html#${tag}">
|
||||||
|
<span class="tag">${tag}</span>
|
||||||
|
</a>
|
||||||
|
`).join(", ")
|
||||||
|
)}</td>
|
||||||
|
</tr>
|
||||||
|
`).join(""),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const categoriesTemplate = await Deno.readTextFile("templates/categories.html");
|
const categoriesTemplate = await Deno.readTextFile("templates/categories.html");
|
||||||
|
|
||||||
function renderCategories(articles: ArticleInfo[]): string {
|
function renderCategories(articles: ArticleInfo[]): string {
|
||||||
@ -176,8 +215,8 @@ function renderCategories(articles: ArticleInfo[]): string {
|
|||||||
|
|
||||||
await Deno.mkdir("build/articles", { recursive: true });
|
await Deno.mkdir("build/articles", { recursive: true });
|
||||||
|
|
||||||
const articlesIdMin = 1;
|
const articlesIdMin = ARTICLES_ID_MIN;
|
||||||
const articlesIdMax = 87;
|
const articlesIdMax = ARTICLES_ID_MAX;
|
||||||
|
|
||||||
const articles: ArticleInfo[] = [];
|
const articles: ArticleInfo[] = [];
|
||||||
for (let id = articlesIdMin; id <= articlesIdMax; ++id) {
|
for (let id = articlesIdMin; id <= articlesIdMax; ++id) {
|
||||||
@ -205,6 +244,12 @@ console.log("Building index...");
|
|||||||
const indexHtml = renderIndex(articles);
|
const indexHtml = renderIndex(articles);
|
||||||
await Deno.writeTextFile("build/articles/index.html", indexHtml);
|
await Deno.writeTextFile("build/articles/index.html", indexHtml);
|
||||||
console.log("Index written to 'build/articles/index.html'!");
|
console.log("Index written to 'build/articles/index.html'!");
|
||||||
|
|
||||||
|
console.log("Building date index...");
|
||||||
|
const dateIndexHtml = renderDateIndex(articles);
|
||||||
|
await Deno.writeTextFile("build/articles/dates.html", dateIndexHtml);
|
||||||
|
console.log("Date index written to 'build/articles/dates.html'!");
|
||||||
|
|
||||||
console.log("Building categories...");
|
console.log("Building categories...");
|
||||||
const categoriesHtml = renderCategories(articles);
|
const categoriesHtml = renderCategories(articles);
|
||||||
await Deno.writeTextFile("build/articles/categories.html", categoriesHtml);
|
await Deno.writeTextFile("build/articles/categories.html", categoriesHtml);
|
||||||
|
@ -20,6 +20,10 @@ table {
|
|||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
td {
|
||||||
|
padding: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
td.article-date {
|
td.article-date {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<meta name="author" content="PROLETARIANREVOLUTION.NET">
|
<meta name="author" content="PROLETARIANREVOLUTION.NET">
|
||||||
<meta name="description" content="Categories">
|
<meta name="description" content="Articles by category">
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
</head>
|
</head>
|
||||||
<body class="index">
|
<body class="index">
|
||||||
@ -16,6 +16,7 @@
|
|||||||
</header>
|
</header>
|
||||||
<nav>
|
<nav>
|
||||||
<a href="index.html">Index</a>
|
<a href="index.html">Index</a>
|
||||||
|
<a href="dates.html">Organized by date</a>
|
||||||
</nav>
|
</nav>
|
||||||
<main>
|
<main>
|
||||||
<h1 id="title">
|
<h1 id="title">
|
||||||
|
37
templates/dates.html
Normal file
37
templates/dates.html
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en-US">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<meta name="author" content="PROLETARIANREVOLUTION.NET">
|
||||||
|
<meta name="description" content="Articles by date">
|
||||||
|
<link rel="stylesheet" href="style.css">
|
||||||
|
</head>
|
||||||
|
<body class="index">
|
||||||
|
<header>
|
||||||
|
Mirror website of
|
||||||
|
<a href="https://proletarianrevolution.net/">
|
||||||
|
PROLETARIANREVOLUTION.NET
|
||||||
|
</a>
|
||||||
|
</header>
|
||||||
|
<nav>
|
||||||
|
<a href="index.html">Index</a>
|
||||||
|
<a href="categories.html">Organized by categories</a>
|
||||||
|
</nav>
|
||||||
|
<main>
|
||||||
|
<h1 id="title">
|
||||||
|
Articles sorted by dates (first to last)
|
||||||
|
</h1>
|
||||||
|
<p>The articles were downloaded $downloadDate.</p>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>Title</th>
|
||||||
|
<th>Author</th>
|
||||||
|
<th>Date added</th>
|
||||||
|
<th>Tags</th>
|
||||||
|
</tr>
|
||||||
|
$articleEntriesByDate
|
||||||
|
</table>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -20,8 +20,10 @@
|
|||||||
</h1>
|
</h1>
|
||||||
<p>The articles were downloaded $downloadDate.</p>
|
<p>The articles were downloaded $downloadDate.</p>
|
||||||
<p>
|
<p>
|
||||||
See also the articles <a href="categories.html"
|
See also the articles organized
|
||||||
>organized by categories</a>.
|
<a href="categories.html">by categories</a>
|
||||||
|
or
|
||||||
|
<a href="dates.html">by dates</a>.
|
||||||
</p>
|
</p>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
|
Loading…
Reference in New Issue
Block a user