A lightweight CMS for a small business site
cmscontent-managementjsonphpmysqladminsmall-business
A single-stylist salon owner needed to edit copy, photos, prices and social links without a developer. Instead of adopting a headless CMS (Strapi, Directus and similar), the existing custom PHP admin was extended: it already had JWT auth and CRUD for services, products and availability, so it was about 80% of the way there, and object storage was already solved in another project. The result is a pattern worth reusing for any small site with one editor.
Data model: one JSON blob per section
CREATE TABLE site_content (
section VARCHAR(64) PRIMARY KEY,
data JSON NOT NULL,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
GET /content(public) returns all rows;PATCH /admin/content/{section}(admin) upserts one. The section name is validated as[a-z_]+, so new sections need no API change.- A missing row means "use the default". Nothing is seeded in the database.
Front end: shipped defaults plus overrides
content-defaults.jsholds the out-of-the-box copy for every section; it is the single source of truth for what a fresh site says.content.js:loadContent()fetches once at startup (in parallel with auth restore),content(section)returns the stored override or the default,setLocalContent()updates the cache after a save. If the fetch fails (API down, CORS during local dev) the site silently renders defaults instead of breaking.- Move essentially all visible marketing copy (hero, highlights, process, stats, testimonials, business hours and contact, brand name, page intros and headings, footer blurb, socials) into content; leave only structural strings in code. The salon ended with 15 sections.
Schema-driven editor
The admin editor is generated from a SCHEMAS array: object sections render as labeled fields,
list sections as rows with add, remove and reorder. Field types include text, textarea, image
(an upload/choose-existing/paste-URL picker) and icon. Adding a section is a schema entry plus a
default.
- Icon fields need a visual grid. A native
<select>cannot render icon-font glyphs (e.g. Material Symbols) in its options, so the picker is a grid of glyph buttons backed by a hidden input. A field can pass its own icon set; Material Symbols has no brand logos, so social links used generic stand-ins.
Show/hide without losing content
Each section has a "Show on site" checkbox. The flags live in a separate content key,
visibility ({section: bool}, absent means visible), so hiding a section never touches its
saved content. The section's Save button PATCHes visibility only if that section's own flag
changed, merging into the last saved map so other sections' unsaved toggles stay unsaved. The
editor shows a "Hidden" badge, and each schema carries a label explaining what hiding does
where it is not obvious (hiding "business" removes both the contact rows and the footer column).
Conventions
- Empty means absent. If a value is blank, drop the whole block, icon and label included. A social link with no URL renders as a decorative span; an empty list hides the row.
- Soften defaults to the business's real scale ("12 stylists" on a one-person salon reads as fake).
- Images go to object storage and are resized on upload (Resizing uploaded photos on the server (PHP GD)).
- Give the owner a change-password screen and nightly database backups (Nightly MySQL/MariaDB backups with mysqldump and cron); a CMS makes the database the only copy of the content.
See also
- A production vanilla-JS single-page app (no framework, no build)
- Resizing uploaded photos on the server (PHP GD)
- Linode (Akamai) Object Storage
- Nightly MySQL/MariaDB backups with mysqldump and cron