refactor(recent-changes): use descriptive field names in RcItemJson

Replace single-letter keys (t, l, d, c, k, e, g) with readable names:
  t → title
  l → link
  d → date
  c → created
  k → type
  e → excerpt
  g → tags

Also remove the unused 'i' (index) field — it was included in the JSON
payload but never accessed by the client script.
This commit is contained in:
Soushi888 2026-03-18 01:53:00 -04:00
parent b649281af2
commit 3584ac9e95
2 changed files with 28 additions and 31 deletions

View File

@ -126,17 +126,15 @@ export default ((userOpts?: Partial<Options>) => {
// JSON data island: all items as compact JSON for progressive client-side injection.
// Links are pre-resolved server-side since the client cannot call resolveRelative.
// The `i` field records each item's index in this array for deduplication tracking.
const allItemsJson = JSON.stringify(
filtered.map((item, idx) => ({
i: idx,
t: item.title,
l: resolveRelative(fileData.slug!, item.link),
d: item.date.getTime(),
c: item.createdDate.getTime(),
k: item.type,
...(opts.showExcerpt && item.excerpt ? { e: item.excerpt } : {}),
...(opts.showTags && item.tags?.length ? { g: item.tags } : {}),
filtered.map((item) => ({
title: item.title,
link: resolveRelative(fileData.slug!, item.link),
date: item.date.getTime(),
created: item.createdDate.getTime(),
type: item.type,
...(opts.showExcerpt && item.excerpt ? { excerpt: item.excerpt } : {}),
...(opts.showTags && item.tags?.length ? { tags: item.tags } : {}),
})),
).replace(/<\//g, "<\\/")

View File

@ -19,14 +19,13 @@ function formatRelativeDate(date: Date, locale: string): string {
}
interface RcItemJson {
i: number
t: string
l: string
d: number // most-recent-activity timestamp
c: number // creation date timestamp
k: "created" | "modified"
e?: string
g?: string[]
title: string
link: string
date: number // most-recent-activity timestamp (ms)
created: number // creation date timestamp (ms)
type: "created" | "modified"
excerpt?: string
tags?: string[]
}
interface RcI18n {
@ -83,9 +82,9 @@ function setupRecentChanges() {
// "created" → ALL notes by creation date (the "New" tab)
// "modified" → only modified notes by modification date
const sortedArrays: Record<string, RcItemJson[]> = {
all: [...allData].sort((a, b) => b.d - a.d),
created: [...allData].sort((a, b) => b.c - a.c),
modified: allData.filter((x) => x.k === "modified").sort((a, b) => b.d - a.d),
all: [...allData].sort((a, b) => b.date - a.date),
created: [...allData].sort((a, b) => b.created - a.created),
modified: allData.filter((x) => x.type === "modified").sort((a, b) => b.date - a.date),
}
// Human-readable descriptions for each tab
@ -102,15 +101,15 @@ function setupRecentChanges() {
function createItemEl(item: RcItemJson, filter: string): HTMLLIElement {
const li = document.createElement("li")
li.className = `recent-change-item ${item.k}`
li.dataset.type = item.k
li.className = `recent-change-item ${item.type}`
li.dataset.type = item.type
const a = document.createElement("a")
a.href = item.l
a.href = item.link
a.className = "recent-change-link internal"
const titleSpan = document.createElement("span")
titleSpan.className = "recent-change-title"
titleSpan.textContent = item.t
titleSpan.textContent = item.title
a.appendChild(titleSpan)
li.appendChild(a)
@ -120,11 +119,11 @@ function setupRecentChanges() {
const typeSpan = document.createElement("span")
typeSpan.className = "recent-change-type"
typeSpan.textContent =
item.k === "created" ? (i18nData.badgeNew ?? "New") : (i18nData.badgeUpdated ?? "Edited")
item.type === "created" ? (i18nData.badgeNew ?? "New") : (i18nData.badgeUpdated ?? "Edited")
meta.appendChild(typeSpan)
// Use creation timestamp for the "New" tab, activity timestamp otherwise
const ts = filter === "created" ? item.c : item.d
const ts = filter === "created" ? item.created : item.date
const dateSpan = document.createElement("span")
dateSpan.className = "recent-change-date"
dateSpan.dataset.timestamp = ts.toString()
@ -133,17 +132,17 @@ function setupRecentChanges() {
li.appendChild(meta)
if (isDetailed && showExcerpt && item.e) {
if (isDetailed && showExcerpt && item.excerpt) {
const p = document.createElement("p")
p.className = "recent-change-excerpt"
p.textContent = item.e
p.textContent = item.excerpt
li.appendChild(p)
}
if (isDetailed && showTags && item.g?.length) {
if (isDetailed && showTags && item.tags?.length) {
const tagsDiv = document.createElement("div")
tagsDiv.className = "recent-change-tags"
item.g.forEach((tag) => {
item.tags.forEach((tag) => {
const tagSpan = document.createElement("span")
tagSpan.className = "recent-change-tag"
tagSpan.textContent = tag