diff --git a/CHANGELOG.md b/CHANGELOG.md index c3e7b04..de3a620 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [2.1.1] - 2026-09-14 +### Changed + +- Renumbered every article's slug to sequential `article-N`, ordered by `publishedAt` (oldest + first), via a one-time PocketBase migration — replaces the previous descriptive slugs at the + owner's explicit request. Not reversible; existing links/indexed URLs using the old slugs now + 404. + ### Fixed - Language switch no longer overlaps the header logo on narrow viewports (~390px, e.g. iPhone 14 diff --git a/pocketbase/pb_migrations/1757500003_renumber_article_slugs.js b/pocketbase/pb_migrations/1757500003_renumber_article_slugs.js new file mode 100644 index 0000000..8e527b9 --- /dev/null +++ b/pocketbase/pb_migrations/1757500003_renumber_article_slugs.js @@ -0,0 +1,35 @@ +/// + +// One-time cleanup: replace every article's slug with a sequential +// "article-N", ordered by publishedAt (oldest first; drafts, which have no +// publishedAt, sort after published articles by creation order). Requested +// explicitly by the site owner, aware this drops the existing descriptive +// slugs and breaks any already-indexed/shared URLs using them. +// +// Two passes with a temporary unique slug in between: assigning final slugs +// in a single pass can collide with another record's current slug that +// hasn't been renamed yet (slug has a unique index). +migrate((app) => { + const articles = app.findAllRecords('articles') + + articles.sort((a, b) => { + const publishedA = a.getString('publishedAt') + const publishedB = b.getString('publishedAt') + if (publishedA && publishedB) return publishedA < publishedB ? -1 : publishedA > publishedB ? 1 : 0 + if (publishedA) return -1 + if (publishedB) return 1 + return a.getString('created') < b.getString('created') ? -1 : 1 + }) + + articles.forEach((record) => { + record.set('slug', `migrating-${record.id}`) + app.save(record) + }) + + articles.forEach((record, index) => { + record.set('slug', `article-${index + 1}`) + app.save(record) + }) +}, (_app) => { + // Not reversible: the original slugs aren't recorded anywhere. +})