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. // 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. // 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( const allItemsJson = JSON.stringify(
filtered.map((item, idx) => ({ filtered.map((item) => ({
i: idx, title: item.title,
t: item.title, link: resolveRelative(fileData.slug!, item.link),
l: resolveRelative(fileData.slug!, item.link), date: item.date.getTime(),
d: item.date.getTime(), created: item.createdDate.getTime(),
c: item.createdDate.getTime(), type: item.type,
k: item.type, ...(opts.showExcerpt && item.excerpt ? { excerpt: item.excerpt } : {}),
...(opts.showExcerpt && item.excerpt ? { e: item.excerpt } : {}), ...(opts.showTags && item.tags?.length ? { tags: item.tags } : {}),
...(opts.showTags && item.tags?.length ? { g: item.tags } : {}),
})), })),
).replace(/<\//g, "<\\/") ).replace(/<\//g, "<\\/")

View File

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