Fix some link issues
This commit is contained in:
parent
7facd7c6a2
commit
d70e0a6dae
5 changed files with 20 additions and 25 deletions
|
@ -45,10 +45,9 @@ const TAGS_MAP = {
|
|||
embed = await getEmbed(game, uploadsResponse);
|
||||
}
|
||||
|
||||
const d = new Date(timestamp);
|
||||
let 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 });
|
||||
const fd = fs.openSync(path + "/index.md", "w+");
|
||||
|
|
|
@ -53,10 +53,9 @@ const feed = new Feed({
|
|||
let frontmatter = data.match(/---\n([\S\s]*?\n)---/m)[1];
|
||||
const { kind, published } = YAML.parse(frontmatter);
|
||||
let timestamp = parseInt(published);
|
||||
const d = new Date(timestamp);
|
||||
let 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.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 d = new Date(timestamp);
|
||||
const link = `https://www.thepaperpilot.org/${kind}/${d.getFullYear()}/${d.getMonth()}/${d.getDate()}/${timestamp}`;
|
||||
const link = `https://www.thepaperpilot.org/${kind}/${getTimestampPath(timestamp)}`;
|
||||
feed.addItem({
|
||||
title: title ?? kind,
|
||||
id: link,
|
||||
|
@ -214,8 +212,7 @@ function insertByDate(posts, kind, timestamp) {
|
|||
}
|
||||
|
||||
function getContentFromTimestamp({ kind, timestamp }) {
|
||||
const d = new Date(timestamp);
|
||||
const filePath = `./site/${kind}/${d.getFullYear()}/${d.getMonth()}/${d.getDate()}/${timestamp}/index.md`;
|
||||
const filePath = `./site/${kind}/${getTimestampPath(timestamp)}/index.md`;
|
||||
const data = fs.readFileSync(filePath).toString();
|
||||
return data.match(/---\n[\S\s]*?\n---\n([\S\s]*)/m)[1]
|
||||
.replace(/<iframe.*<\/iframe>/, '')
|
||||
|
|
|
@ -104,10 +104,9 @@ let createdPosts = 0;
|
|||
|
||||
const tag = slugify(aliases_map[subreddit.toLowerCase()] ?? subreddit);
|
||||
|
||||
const d = new Date(timestamp);
|
||||
let 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 });
|
||||
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 d = new Date(timestamp);
|
||||
let 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 });
|
||||
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 subreddit = await extractSubreddit(submission.subreddit);
|
||||
|
||||
const d = new Date(timestamp);
|
||||
let 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 });
|
||||
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 subreddit = await extractSubreddit(submission.subreddit);
|
||||
|
||||
const d = new Date(timestamp);
|
||||
let 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 });
|
||||
const fd = fs.openSync(path + "/index.md", "w+");
|
||||
|
|
|
@ -214,10 +214,9 @@ async function process(auth) {
|
|||
continue;
|
||||
}
|
||||
|
||||
const d = new Date(timestamp);
|
||||
let 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 });
|
||||
const fd = fs.openSync(path + "/index.md", "w+");
|
||||
|
@ -355,10 +354,9 @@ tags: [${encodeString(tag, 2)}]
|
|||
</div>
|
||||
</div>`;
|
||||
|
||||
const d = new Date(timestamp);
|
||||
let 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 });
|
||||
const fd = fs.openSync(path + "/index.md", "w+");
|
||||
|
@ -695,10 +693,9 @@ async function likeVideo({ videoId, auth, kind }) {
|
|||
</div>
|
||||
</div>`;
|
||||
|
||||
const d = new Date(timestamp);
|
||||
let 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 });
|
||||
const fd = fs.openSync(path + "/index.md", "w+");
|
||||
|
|
12
utils.js
12
utils.js
|
@ -10,7 +10,7 @@ const KIND_ACTIONS_MAP = {
|
|||
bookmark: "❤️",
|
||||
favorite: "⭐",
|
||||
reply: "💬",
|
||||
"": "📝"
|
||||
[undefined]: "📝"
|
||||
}
|
||||
|
||||
const KIND_VERBS_MAP = {
|
||||
|
@ -42,7 +42,7 @@ function getActionDescription({ kind, timestamp }) {
|
|||
` on <time class="dt-published" datetime="${tsString}" title="${tsString}">
|
||||
${ts.toLocaleDateString()}
|
||||
</time>` : '';
|
||||
const path = `/posts/${ts.getFullYear()}/${ts.getMonth()}/${ts.getDate()}/${timestamp}`;
|
||||
const path = `/${kind}/${getTimestampPath(timestamp)}`;
|
||||
return `<div class="action-description">
|
||||
<span class="action">${KIND_ACTIONS_MAP[kind]}</span>
|
||||
<a class="p-name u-url h-card" href="/about">The Paper Pilot</a>
|
||||
|
@ -239,6 +239,11 @@ function linkify(str) {
|
|||
'<a href="$&">$&</a>');
|
||||
}
|
||||
|
||||
function getTimestampPath(timestamp) {
|
||||
const d = new Date(timestamp);
|
||||
return `${d.getFullYear()}/${d.getMonth() + 1}/${d.getDate() + 1}/${timestamp}`;
|
||||
}
|
||||
|
||||
function monthString(month) {
|
||||
return ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][month];
|
||||
}
|
||||
|
@ -275,5 +280,6 @@ module.exports = {
|
|||
getArchivePreview,
|
||||
getMediaUrl,
|
||||
linkify,
|
||||
sanitize
|
||||
sanitize,
|
||||
getTimestampPath
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue