Skip to content

Commit

Permalink
Show published date for events, not last update
Browse files Browse the repository at this point in the history
  • Loading branch information
zephraph committed Oct 4, 2024
1 parent f7fe65c commit 55c5fd3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/my-remark/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,22 @@ export const myRemark: RemarkPlugin = () => {
}

if (fm.published) {
const publishedLabel = {
let dateLabel = {
type: "html" as const,
value: `<p><sup ${
fm.updated ? `title="Published on ${fm.published}"` : ""
}>${fm.updated ?? fm.published}</sup></p>`,
value: `<p><sup>${fm.published}</sup></p>`,
};

// If the document is associated with an event, skip showing the updated date
if (fm.updated && !fm.tags?.includes("events")) {
dateLabel.value = `<p><sup title="Published on ${fm.published}">${fm.updated}</sup></p>`;
}

const firstHeadingIndex = root.children.findIndex(
(node) => node.type === "heading" && node.depth === 1
);

if (firstHeadingIndex !== -1) {
root.children.splice(firstHeadingIndex + 1, 0, publishedLabel);
root.children.splice(firstHeadingIndex + 1, 0, dateLabel);
}
}
};
Expand Down

0 comments on commit 55c5fd3

Please sign in to comment.