mirror of
https://github.com/kbenestad/mdcms.git
synced 2026-06-18 15:24:32 +00:00
Update post listing tags to use created field throughout
Tag names changed from posts-date-*/posts-datetime-* to posts-created-*. Renderer updated to filter, sort, group, and display using the created field from search.json. Page meta display also updated to drop date/datetime fallbacks. Samplesite posts and pages updated to match. https://claude.ai/code/session_013A4egzphocyto9bvZ76dxf
This commit is contained in:
parent
a6eb3119e0
commit
5e4612c01d
11 changed files with 29 additions and 44 deletions
|
|
@ -148,13 +148,13 @@ Embed post lists in pages using fenced blocks:
|
||||||
|
|
||||||
````markdown
|
````markdown
|
||||||
```mdcms
|
```mdcms
|
||||||
posts-datetime-reversechronological
|
posts-created-reversechronological
|
||||||
limit: 10
|
limit: 10
|
||||||
paginate: yes
|
paginate: yes
|
||||||
```
|
```
|
||||||
````
|
````
|
||||||
|
|
||||||
Reliable tags (others are known-broken): `posts-datetime-chronological-byyearmonth`, `posts-datetime-reversechronological`. Use `created` frontmatter (format: `YYYY-MM-DD HH:MM`) for posts.
|
Reliable tags (others are known-broken): `posts-created-chronological-byyearmonth`, `posts-created-reversechronological`. Use `created` frontmatter (format: `YYYY-MM-DD HH:MM`) for posts.
|
||||||
|
|
||||||
## Release workflow
|
## Release workflow
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1369,14 +1369,14 @@ function fmtDatetime(dtStr) {
|
||||||
|
|
||||||
function parsePostTagName(name) {
|
function parsePostTagName(name) {
|
||||||
var m = name.match(
|
var m = name.match(
|
||||||
/^posts-(date|datetime)-(chronological|reversechronological)(?:-(byyear|byyearmonth|lastyear|lastmonth))?$/
|
/^posts-created-(chronological|reversechronological)(?:-(byyear|byyearmonth|lastyear|lastmonth))?$/
|
||||||
);
|
);
|
||||||
if (!m) return null;
|
if (!m) return null;
|
||||||
return { field: m[1], order: m[2], modifier: m[3] || null };
|
return { order: m[1], modifier: m[2] || null };
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPostEntries(parsed, options) {
|
function getPostEntries(parsed, options) {
|
||||||
const { field, order, modifier } = parsed;
|
const { order, modifier } = parsed;
|
||||||
|
|
||||||
// Start with posts from search index
|
// Start with posts from search index
|
||||||
let posts = (searchIndex || []).filter(function(e) {
|
let posts = (searchIndex || []).filter(function(e) {
|
||||||
|
|
@ -1389,11 +1389,7 @@ function fmtDatetime(dtStr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Field filter
|
// Field filter
|
||||||
if (field === 'datetime') {
|
posts = posts.filter(function(e) { return !!e.created; });
|
||||||
posts = posts.filter(function(e) { return !!e.datetime; });
|
|
||||||
} else {
|
|
||||||
posts = posts.filter(function(e) { return !!e.date; });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Time-window filter
|
// Time-window filter
|
||||||
if (modifier === 'lastyear' || modifier === 'lastmonth') {
|
if (modifier === 'lastyear' || modifier === 'lastmonth') {
|
||||||
|
|
@ -1402,15 +1398,13 @@ function fmtDatetime(dtStr) {
|
||||||
if (modifier === 'lastyear') cutoff.setDate(cutoff.getDate() - 365);
|
if (modifier === 'lastyear') cutoff.setDate(cutoff.getDate() - 365);
|
||||||
else cutoff.setDate(cutoff.getDate() - 30);
|
else cutoff.setDate(cutoff.getDate() - 30);
|
||||||
posts = posts.filter(function(e) {
|
posts = posts.filter(function(e) {
|
||||||
var raw = field === 'datetime' ? e.datetime.replace(' ', 'T') : e.date;
|
return new Date(e.created.replace(' ', 'T')) >= cutoff;
|
||||||
return new Date(raw) >= cutoff;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort
|
// Sort
|
||||||
var sortKey = field === 'datetime' ? 'datetime' : 'date';
|
|
||||||
posts.sort(function(a, b) {
|
posts.sort(function(a, b) {
|
||||||
var da = a[sortKey] || '', db = b[sortKey] || '';
|
var da = a.created || '', db = b.created || '';
|
||||||
return order === 'chronological' ? da.localeCompare(db) : db.localeCompare(da);
|
return order === 'chronological' ? da.localeCompare(db) : db.localeCompare(da);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -1523,7 +1517,6 @@ function fmtDatetime(dtStr) {
|
||||||
|
|
||||||
var opts = tag.options;
|
var opts = tag.options;
|
||||||
var posts = getPostEntries(parsed, opts);
|
var posts = getPostEntries(parsed, opts);
|
||||||
var field = parsed.field;
|
|
||||||
var modifier = parsed.modifier;
|
var modifier = parsed.modifier;
|
||||||
var paginate = opts.paginate || 'no';
|
var paginate = opts.paginate || 'no';
|
||||||
var limitVal = opts.limit || 'all';
|
var limitVal = opts.limit || 'all';
|
||||||
|
|
@ -1532,7 +1525,7 @@ function fmtDatetime(dtStr) {
|
||||||
// Format each entry
|
// Format each entry
|
||||||
var formatted = posts.map(function(p) {
|
var formatted = posts.map(function(p) {
|
||||||
return {
|
return {
|
||||||
display: field === 'datetime' ? fmtDatetime(p.datetime) : fmtDate(p.date),
|
display: fmtDatetime(p.created),
|
||||||
title: p.title,
|
title: p.title,
|
||||||
file: p.file
|
file: p.file
|
||||||
};
|
};
|
||||||
|
|
@ -1565,12 +1558,10 @@ function fmtDatetime(dtStr) {
|
||||||
|
|
||||||
// Grouped by year (or year+month)
|
// Grouped by year (or year+month)
|
||||||
function getYear(p) {
|
function getYear(p) {
|
||||||
var d = field === 'datetime' ? p.datetime : p.date;
|
return p.created ? p.created.substring(0, 4) : 'Unknown';
|
||||||
return d ? d.substring(0, 4) : 'Unknown';
|
|
||||||
}
|
}
|
||||||
function getYearMonth(p) {
|
function getYearMonth(p) {
|
||||||
var d = field === 'datetime' ? p.datetime : p.date;
|
return p.created ? p.created.substring(0, 7) : 'Unknown';
|
||||||
return d ? d.substring(0, 7) : 'Unknown';
|
|
||||||
}
|
}
|
||||||
function monthLabel(ym) {
|
function monthLabel(ym) {
|
||||||
var m = parseInt(ym.substring(5, 7), 10);
|
var m = parseInt(ym.substring(5, 7), 10);
|
||||||
|
|
@ -2189,12 +2180,12 @@ function fmtDatetime(dtStr) {
|
||||||
hydrateMdcmsTags();
|
hydrateMdcmsTags();
|
||||||
|
|
||||||
const firstH = contentEl.querySelector('.md-content h1, .md-content h2');
|
const firstH = contentEl.querySelector('.md-content h1, .md-content h2');
|
||||||
if (firstH && (meta.author || meta.created || meta.date || meta.datetime)) {
|
if (firstH && (meta.author || meta.created)) {
|
||||||
const metaEl = document.createElement('div');
|
const metaEl = document.createElement('div');
|
||||||
metaEl.className = 'page-meta';
|
metaEl.className = 'page-meta';
|
||||||
let metaText = '';
|
let metaText = '';
|
||||||
if (meta.author) metaText += meta.author;
|
if (meta.author) metaText += meta.author;
|
||||||
const displayDate = meta.datetime || meta.date || meta.created;
|
const displayDate = meta.created;
|
||||||
if (displayDate) {
|
if (displayDate) {
|
||||||
if (metaText) metaText += ' | ';
|
if (metaText) metaText += ' | ';
|
||||||
metaText += 'Published ' + formatDate(displayDate);
|
metaText += 'Published ' + formatDate(displayDate);
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ If you want to test `MD-CMS` you can grab `samplesite` from the repo and place t
|
||||||
## Reverse chronological (newest first)
|
## Reverse chronological (newest first)
|
||||||
|
|
||||||
```mdcms
|
```mdcms
|
||||||
posts-date-reversechronological
|
posts-created-reversechronological
|
||||||
limit: 3
|
limit: 3
|
||||||
paginate: no
|
paginate: no
|
||||||
```
|
```
|
||||||
|
|
@ -26,25 +26,25 @@ paginate: no
|
||||||
## Chronological (oldest first)
|
## Chronological (oldest first)
|
||||||
|
|
||||||
```mdcms
|
```mdcms
|
||||||
posts-date-chronological
|
posts-created-chronological
|
||||||
limit: all
|
limit: all
|
||||||
paginate: none
|
paginate: none
|
||||||
```
|
```
|
||||||
|
|
||||||
## By year (date, reverse chrono)
|
## By year (reverse chrono)
|
||||||
|
|
||||||
```mdcms
|
```mdcms
|
||||||
posts-date-reversechronological-byyear
|
posts-created-reversechronological-byyear
|
||||||
limit: all
|
limit: all
|
||||||
defaultyear: current
|
defaultyear: current
|
||||||
selectyear: yes
|
selectyear: yes
|
||||||
paginate: none
|
paginate: none
|
||||||
```
|
```
|
||||||
|
|
||||||
## By year+month (datetime, chrono)
|
## By year+month (chrono)
|
||||||
|
|
||||||
```mdcms
|
```mdcms
|
||||||
posts-datetime-chronological-byyearmonth
|
posts-created-chronological-byyearmonth
|
||||||
limit: all
|
limit: all
|
||||||
defaultyear: 2024
|
defaultyear: 2024
|
||||||
selectyear: yes
|
selectyear: yes
|
||||||
|
|
@ -53,7 +53,7 @@ selectyear: yes
|
||||||
## Last 30 days
|
## Last 30 days
|
||||||
|
|
||||||
```mdcms
|
```mdcms
|
||||||
posts-date-reversechronological-lastmonth
|
posts-created-reversechronological-lastmonth
|
||||||
limit: all
|
limit: all
|
||||||
paginate: none
|
paginate: none
|
||||||
```
|
```
|
||||||
|
|
@ -61,7 +61,7 @@ paginate: none
|
||||||
## Paginated (2 per page)
|
## Paginated (2 per page)
|
||||||
|
|
||||||
```mdcms
|
```mdcms
|
||||||
posts-datetime-reversechronological
|
posts-created-reversechronological
|
||||||
limit: 2
|
limit: 2
|
||||||
paginate: yes
|
paginate: yes
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ Stay up to date with announcements, product updates, and industry insights from
|
||||||
## All Posts
|
## All Posts
|
||||||
|
|
||||||
```mdcms
|
```mdcms
|
||||||
posts-date-reversechronological-byyear
|
posts-created-reversechronological-byyear
|
||||||
limit: all
|
limit: all
|
||||||
defaultyear: current
|
defaultyear: current
|
||||||
selectyear: yes
|
selectyear: yes
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ Bli oppdatert med kunngjøringer, produktoppdateringer og bransjeinnsikter fra A
|
||||||
## Alle innlegg
|
## Alle innlegg
|
||||||
|
|
||||||
```mdcms
|
```mdcms
|
||||||
posts-date-reversechronological-byyear
|
posts-created-reversechronological-byyear
|
||||||
limit: all
|
limit: all
|
||||||
defaultyear: current
|
defaultyear: current
|
||||||
selectyear: yes
|
selectyear: yes
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
---
|
---
|
||||||
title: Q4 2022 Performance Report
|
title: Q4 2022 Performance Report
|
||||||
date: 2022-11-15
|
created: 2022-11-15 09:00
|
||||||
datetime: 2022-11-15 09:00
|
|
||||||
author: Sarah Chen
|
author: Sarah Chen
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
---
|
---
|
||||||
title: Introducing Advanced Analytics Dashboard
|
title: Introducing Advanced Analytics Dashboard
|
||||||
date: 2023-03-22
|
created: 2023-03-22 14:30
|
||||||
datetime: 2023-03-22 14:30
|
|
||||||
author: David Okonkwo
|
author: David Okonkwo
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
---
|
---
|
||||||
title: Security Update - November 2023
|
title: Security Update - November 2023
|
||||||
date: 2023-11-10
|
created: 2023-11-10 11:45
|
||||||
datetime: 2023-11-10 11:45
|
|
||||||
author: Security Team
|
author: Security Team
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
---
|
---
|
||||||
title: 2024 Product Roadmap
|
title: 2024 Product Roadmap
|
||||||
date: 2024-01-30
|
created: 2024-01-30 10:00
|
||||||
datetime: 2024-01-30 10:00
|
|
||||||
author: David Okonkwo
|
author: David Okonkwo
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
---
|
---
|
||||||
title: Q2 2024 Customer Success Stories
|
title: Q2 2024 Customer Success Stories
|
||||||
date: 2024-07-08
|
created: 2024-07-08 15:20
|
||||||
datetime: 2024-07-08 15:20
|
|
||||||
author: Maria Garcia
|
author: Maria Garcia
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
---
|
---
|
||||||
title: Version 9.0 Released — A New Era
|
title: Version 9.0 Released — A New Era
|
||||||
date: 2026-04-10
|
created: 2026-04-10 13:00
|
||||||
datetime: 2026-04-10 13:00
|
|
||||||
author: Sarah Chen
|
author: Sarah Chen
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue