Fix some link issues

This commit is contained in:
thepaperpilot 2024-09-14 10:30:41 -05:00
parent 7facd7c6a2
commit d70e0a6dae
5 changed files with 20 additions and 25 deletions

View file

@ -45,10 +45,9 @@ const TAGS_MAP = {
embed = await getEmbed(game, uploadsResponse); embed = await getEmbed(game, uploadsResponse);
} }
const d = new Date(timestamp);
let path; let path;
for (timestamp--; path == null || fs.existsSync(path);) { for (timestamp--; path == null || fs.existsSync(path);) {
path = `./site/article/${d.getFullYear()}/${d.getMonth()}/${d.getDate()}/${++timestamp}`; path = `./site/article/${getTimestampPath(++timestamp)}`;
} }
fs.mkdirSync(path, { recursive: true }); fs.mkdirSync(path, { recursive: true });
const fd = fs.openSync(path + "/index.md", "w+"); const fd = fs.openSync(path + "/index.md", "w+");

View file

@ -53,10 +53,9 @@ const feed = new Feed({
let frontmatter = data.match(/---\n([\S\s]*?\n)---/m)[1]; let frontmatter = data.match(/---\n([\S\s]*?\n)---/m)[1];
const { kind, published } = YAML.parse(frontmatter); const { kind, published } = YAML.parse(frontmatter);
let timestamp = parseInt(published); let timestamp = parseInt(published);
const d = new Date(timestamp);
let path; let path;
for (timestamp--; path == null || fs.existsSync(path);) { for (timestamp--; path == null || fs.existsSync(path);) {
path = `./site/${kind}/${d.getFullYear()}/${d.getMonth()}/${d.getDate()}/${++timestamp}`; path = `./site/${kind}/${getTimestampPath(++timestamp)}`;
} }
fs.mkdirSync(path, { recursive: true }); fs.mkdirSync(path, { recursive: true });
fs.copyFileSync(filePath, path + "/index.md"); fs.copyFileSync(filePath, path + "/index.md");
@ -180,8 +179,7 @@ function processPost(dir, file, resolve) {
const content = data.match(/---\n[\S\s]*?\n---\n([\S\s]*)/m)[1]; const content = data.match(/---\n[\S\s]*?\n---\n([\S\s]*)/m)[1];
const d = new Date(timestamp); const link = `https://www.thepaperpilot.org/${kind}/${getTimestampPath(timestamp)}`;
const link = `https://www.thepaperpilot.org/${kind}/${d.getFullYear()}/${d.getMonth()}/${d.getDate()}/${timestamp}`;
feed.addItem({ feed.addItem({
title: title ?? kind, title: title ?? kind,
id: link, id: link,
@ -214,8 +212,7 @@ function insertByDate(posts, kind, timestamp) {
} }
function getContentFromTimestamp({ kind, timestamp }) { function getContentFromTimestamp({ kind, timestamp }) {
const d = new Date(timestamp); const filePath = `./site/${kind}/${getTimestampPath(timestamp)}/index.md`;
const filePath = `./site/${kind}/${d.getFullYear()}/${d.getMonth()}/${d.getDate()}/${timestamp}/index.md`;
const data = fs.readFileSync(filePath).toString(); const data = fs.readFileSync(filePath).toString();
return data.match(/---\n[\S\s]*?\n---\n([\S\s]*)/m)[1] return data.match(/---\n[\S\s]*?\n---\n([\S\s]*)/m)[1]
.replace(/<iframe.*<\/iframe>/, '') .replace(/<iframe.*<\/iframe>/, '')

View file

@ -104,10 +104,9 @@ let createdPosts = 0;
const tag = slugify(aliases_map[subreddit.toLowerCase()] ?? subreddit); const tag = slugify(aliases_map[subreddit.toLowerCase()] ?? subreddit);
const d = new Date(timestamp);
let path; let path;
for (timestamp--; path == null || fs.existsSync(path);) { for (timestamp--; path == null || fs.existsSync(path);) {
path = `./site/${body ? 'article' : 'bookmark'}/${d.getFullYear()}/${d.getMonth()}/${d.getDate()}/${++timestamp}`; path = `./site/${body ? 'article' : 'bookmark'}/${getTimestampPath(++timestamp)}`;
} }
fs.mkdirSync(path, { recursive: true }); fs.mkdirSync(path, { recursive: true });
const fd = fs.openSync(path + "/index.md", "w+"); const fd = fs.openSync(path + "/index.md", "w+");
@ -225,10 +224,9 @@ tags: [${encodeString(tag, 2)}]
})) ?? []); })) ?? []);
const tag = slugify(aliases_map[subreddit.toLowerCase()] ?? subreddit); const tag = slugify(aliases_map[subreddit.toLowerCase()] ?? subreddit);
const d = new Date(timestamp);
let path; let path;
for (timestamp--; path == null || fs.existsSync(path);) { for (timestamp--; path == null || fs.existsSync(path);) {
path = `./site/reply/${d.getFullYear()}/${d.getMonth()}/${d.getDate()}/${++timestamp}`; path = `./site/reply/${getTimestampPath(++timestamp)}`;
} }
fs.mkdirSync(path, { recursive: true }); fs.mkdirSync(path, { recursive: true });
const fd = fs.openSync(path + "/index.md", "w+"); const fd = fs.openSync(path + "/index.md", "w+");
@ -393,10 +391,9 @@ async function like_post(id, permalink, action = "auto") {
const author = extractUsername(await submission.author); const author = extractUsername(await submission.author);
const subreddit = await extractSubreddit(submission.subreddit); const subreddit = await extractSubreddit(submission.subreddit);
const d = new Date(timestamp);
let path; let path;
for (timestamp--; path == null || fs.existsSync(path);) { for (timestamp--; path == null || fs.existsSync(path);) {
path = `./site/${action}/${d.getFullYear()}/${d.getMonth()}/${d.getDate()}/${++timestamp}`; path = `./site/${action}/${getTimestampPath(++timestamp)}`;
} }
fs.mkdirSync(path, { recursive: true }); fs.mkdirSync(path, { recursive: true });
const fd = fs.openSync(path + "/index.md", "w+"); const fd = fs.openSync(path + "/index.md", "w+");
@ -451,10 +448,9 @@ async function like_comment(id, permalink, action = "repost") {
const author = extractUsername(await comment.author); const author = extractUsername(await comment.author);
const subreddit = await extractSubreddit(submission.subreddit); const subreddit = await extractSubreddit(submission.subreddit);
const d = new Date(timestamp);
let path; let path;
for (timestamp--; path == null || fs.existsSync(path);) { for (timestamp--; path == null || fs.existsSync(path);) {
path = `./site/${action}/${d.getFullYear()}/${d.getMonth()}/${d.getDate()}/${++timestamp}`; path = `./site/${action}/${getTimestampPath(++timestamp)}`;
} }
fs.mkdirSync(path, { recursive: true }); fs.mkdirSync(path, { recursive: true });
const fd = fs.openSync(path + "/index.md", "w+"); const fd = fs.openSync(path + "/index.md", "w+");

View file

@ -214,10 +214,9 @@ async function process(auth) {
continue; continue;
} }
const d = new Date(timestamp);
let path; let path;
for (timestamp--; path == null || fs.existsSync(path);) { for (timestamp--; path == null || fs.existsSync(path);) {
path = `./site/reply/${d.getFullYear()}/${d.getMonth()}/${d.getDate()}/${++timestamp}`; path = `./site/reply/${getTimestampPath(++timestamp)}`;
} }
fs.mkdirSync(path, { recursive: true }); fs.mkdirSync(path, { recursive: true });
const fd = fs.openSync(path + "/index.md", "w+"); const fd = fs.openSync(path + "/index.md", "w+");
@ -355,10 +354,9 @@ tags: [${encodeString(tag, 2)}]
</div> </div>
</div>`; </div>`;
const d = new Date(timestamp);
let path; let path;
for (timestamp--; path == null || fs.existsSync(path);) { for (timestamp--; path == null || fs.existsSync(path);) {
path = `./site/bookmark/${d.getFullYear()}/${d.getMonth()}/${d.getDate()}/${++timestamp}`; path = `./site/bookmark/${getTimestampPath(++timestamp)}`;
} }
fs.mkdirSync(path, { recursive: true }); fs.mkdirSync(path, { recursive: true });
const fd = fs.openSync(path + "/index.md", "w+"); const fd = fs.openSync(path + "/index.md", "w+");
@ -695,10 +693,9 @@ async function likeVideo({ videoId, auth, kind }) {
</div> </div>
</div>`; </div>`;
const d = new Date(timestamp);
let path; let path;
for (timestamp--; path == null || fs.existsSync(path);) { for (timestamp--; path == null || fs.existsSync(path);) {
path = `./site/${kind}/${d.getFullYear()}/${d.getMonth()}/${d.getDate()}/${++timestamp}`; path = `./site/${kind}/${getTimestampPath(++timestamp)}`;
} }
fs.mkdirSync(path, { recursive: true }); fs.mkdirSync(path, { recursive: true });
const fd = fs.openSync(path + "/index.md", "w+"); const fd = fs.openSync(path + "/index.md", "w+");

View file

@ -10,7 +10,7 @@ const KIND_ACTIONS_MAP = {
bookmark: "❤️", bookmark: "❤️",
favorite: "⭐", favorite: "⭐",
reply: "💬", reply: "💬",
"": "📝" [undefined]: "📝"
} }
const KIND_VERBS_MAP = { const KIND_VERBS_MAP = {
@ -42,7 +42,7 @@ function getActionDescription({ kind, timestamp }) {
` on <time class="dt-published" datetime="${tsString}" title="${tsString}"> ` on <time class="dt-published" datetime="${tsString}" title="${tsString}">
${ts.toLocaleDateString()} ${ts.toLocaleDateString()}
</time>` : ''; </time>` : '';
const path = `/posts/${ts.getFullYear()}/${ts.getMonth()}/${ts.getDate()}/${timestamp}`; const path = `/${kind}/${getTimestampPath(timestamp)}`;
return `<div class="action-description"> return `<div class="action-description">
<span class="action">${KIND_ACTIONS_MAP[kind]}</span> <span class="action">${KIND_ACTIONS_MAP[kind]}</span>
<a class="p-name u-url h-card" href="/about">The Paper Pilot</a> <a class="p-name u-url h-card" href="/about">The Paper Pilot</a>
@ -239,6 +239,11 @@ function linkify(str) {
'<a href="$&">$&</a>'); '<a href="$&">$&</a>');
} }
function getTimestampPath(timestamp) {
const d = new Date(timestamp);
return `${d.getFullYear()}/${d.getMonth() + 1}/${d.getDate() + 1}/${timestamp}`;
}
function monthString(month) { function monthString(month) {
return ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][month]; return ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][month];
} }
@ -275,5 +280,6 @@ module.exports = {
getArchivePreview, getArchivePreview,
getMediaUrl, getMediaUrl,
linkify, linkify,
sanitize sanitize,
getTimestampPath
}; };