mirror of
https://github.com/andwati/andwati.com.git
synced 2026-11-24 01:18:47 +00:00
Wire Strapi to content/ via a two-way file sync provider
Adds slug (uid) fields to all four content types so Strapi documents can be matched to files deterministically, plus: - apps/cms/src/utils/content-file.ts: read/write/delete the +++ TOML frontmatter files, using smol-toml's TomlDate so dates round-trip as bare local dates (matching the legacy Zola format), not quoted datetime strings. - apps/cms/src/utils/content-sync.ts: per-type frontmatter <-> Strapi field mappings, a boot-time importer that upserts every content/ file into Strapi by slug, and a Document Service middleware that writes any create/update/delete made through Strapi straight back to the same files. Strapi's SQLite DB is now genuinely a disposable cache: content/ stays buildable and readable with Strapi entirely absent, and restarting Strapi rebuilds its DB from content/ with no duplicates (matched by slug). Verified end-to-end: fresh boot imports all seed files once; a second boot re-imports idempotently (0 created, all matched by slug); create/ update/delete through the content-manager API all correctly write to and remove the corresponding file on disk.
This commit is contained in:
+14
-14
@@ -1,20 +1,20 @@
|
||||
// import type { Core } from '@strapi/strapi';
|
||||
import type { Core } from "@strapi/strapi";
|
||||
import {
|
||||
importContentFromDisk,
|
||||
registerContentSync,
|
||||
} from "./utils/content-sync";
|
||||
|
||||
export default {
|
||||
/**
|
||||
* An asynchronous register function that runs before
|
||||
* your application is initialized.
|
||||
*
|
||||
* This gives you an opportunity to extend code.
|
||||
*/
|
||||
register(/* { strapi }: { strapi: Core.Strapi } */) {},
|
||||
register() {},
|
||||
|
||||
/**
|
||||
* An asynchronous bootstrap function that runs before
|
||||
* your application gets started.
|
||||
*
|
||||
* This gives you an opportunity to set up your data model,
|
||||
* run jobs, or perform some special logic.
|
||||
* content/ is the source of truth (see content/README.md). On boot we
|
||||
* import every file into Strapi's DB (a disposable cache), then register
|
||||
* a Document Service middleware that writes any create/update/delete made
|
||||
* through Strapi straight back to the same files.
|
||||
*/
|
||||
bootstrap(/* { strapi }: { strapi: Core.Strapi } */) {},
|
||||
async bootstrap({ strapi }: { strapi: Core.Strapi }) {
|
||||
registerContentSync(strapi as never);
|
||||
await importContentFromDisk(strapi as never);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user