From 323c2c29e1ba692e785e8b2666cc199291f10437 Mon Sep 17 00:00:00 2001 From: "Schero D." Date: Tue, 17 Nov 2026 22:35:55 +0100 Subject: [PATCH 1/4] docs(readme): consistent badge row Use the shared six-badge row (npm version, monthly downloads, CI, license, Strapi peer floor, docs site) with absolute URLs, and show the same row in the Pages hero. Co-Authored-By: Claude Opus 5.5 --- README.md | 7 ++++--- docs/site/index.html | 39 +++++++++++++++++++++++++++++++++++++++ docs/site/site-extra.css | 16 ++++++++++++++++ 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1035612..37f6c30 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,10 @@ to external servers. [![npm version](https://img.shields.io/npm/v/strapi-plugin-magic-mark.svg)](https://www.npmjs.com/package/strapi-plugin-magic-mark) [![npm downloads](https://img.shields.io/npm/dm/strapi-plugin-magic-mark.svg)](https://www.npmjs.com/package/strapi-plugin-magic-mark) -[![Test & Verify](https://github.com/Schero94/Magicmark/actions/workflows/test.yml/badge.svg)](https://github.com/Schero94/Magicmark/actions/workflows/test.yml) -[![Strapi 5.57+](https://img.shields.io/badge/Strapi-5.57%2B-4945ff.svg)](#compatibility) -[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Schero94/Magicmark/blob/main/LICENSE) +[![CI](https://img.shields.io/github/actions/workflow/status/Schero94/Magicmark/test.yml?branch=main&label=CI&logo=github)](https://github.com/Schero94/Magicmark/actions/workflows/test.yml?query=branch%3Amain) +[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/Schero94/Magicmark/blob/main/LICENSE) +[![Strapi 5.57+](https://img.shields.io/badge/Strapi-5.57%2B-4945FF.svg)](https://github.com/Schero94/Magicmark#compatibility) +[![Docs](https://img.shields.io/badge/docs-project%20site-6d4aff.svg)](https://schero94.github.io/Magicmark/) Website: [schero94.github.io/Magicmark](https://schero94.github.io/Magicmark/) · npm: [strapi-plugin-magic-mark](https://www.npmjs.com/package/strapi-plugin-magic-mark) · diff --git a/docs/site/index.html b/docs/site/index.html index e914d93..ad69328 100644 --- a/docs/site/index.html +++ b/docs/site/index.html @@ -96,6 +96,45 @@

Save the view. Open it again with one click.

Source on GitHub npm install strapi-plugin-magic-mark +

+ npm version + npm downloads + CI + License: MIT + Strapi 5.57+ + Docs +

Strapi 5.57+ (tested on 5.61) Node 22 and 24 diff --git a/docs/site/site-extra.css b/docs/site/site-extra.css index f8aa75a..14a3b66 100644 --- a/docs/site/site-extra.css +++ b/docs/site/site-extra.css @@ -216,3 +216,19 @@ details p { width: 2rem; height: 2rem; } + +/* Project status badges in the hero: same row as the README. */ +.shields { + display: flex; + flex-wrap: wrap; + gap: 0.4rem; + margin: 1.25rem 0 0; +} +.shields a { + display: inline-flex; +} +.shields img { + display: block; + width: auto; + height: 20px; +} From 4737ca984ea68c9fa35edbc43c0ace928121ada6 Mon Sep 17 00:00:00 2001 From: "Schero D." Date: Tue, 17 Nov 2026 22:35:55 +0100 Subject: [PATCH 2/4] test: guard the README badge row Fails when the badge row is missing or out of order, a badge or link is relative, the Strapi badge differs from the @strapi/strapi peer floor, or the npm badges name another package. Co-Authored-By: Claude Opus 5.5 --- tests/readme-badges.test.cjs | 153 +++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 tests/readme-badges.test.cjs diff --git a/tests/readme-badges.test.cjs b/tests/readme-badges.test.cjs new file mode 100644 index 0000000..fc011ea --- /dev/null +++ b/tests/readme-badges.test.cjs @@ -0,0 +1,153 @@ +'use strict'; + +const test = require('node:test'); +const assert = require('node:assert/strict'); +const { existsSync, readFileSync } = require('node:fs'); +const path = require('node:path'); + +const root = path.resolve(__dirname, '..'); + +/** + * Badge row contract. Every plugin README starts with the same six shields.io badges in the + * same order (npm version, monthly downloads, CI, license, Strapi floor, docs site). The README + * ships in the npm package and is rendered on npmjs.com and the Strapi marketplace, which do not + * resolve relative URLs, so every badge image and link is absolute. The Strapi badge must state + * the floor of the @strapi/strapi peer dependency and the npm badges must name this package. + */ + +const WORKFLOW = 'test.yml'; +const COMPAT_ANCHOR = 'compatibility'; + +const read = (file) => readFileSync(path.join(root, file), 'utf8'); +const pkg = JSON.parse(read('package.json')); +const readme = read('README.md'); +const slug = pkg.repository.url.match(/github\.com\/([^/]+\/[^/.]+)/)[1]; +const BADGE_LINE = /^\[!\[([^\]]+)\]\((\S+)\)\]\((\S+)\)$/; + +/** + * Reads the first block of consecutive badge lines above the first "## " heading. + * + * @returns {{ alt: string, img: string, href: string }[]} The badges in README order. + */ +function badgeRow() { + const lines = readme.split('\n'); + const end = lines.findIndex((line) => line.startsWith('## ')); + const head = lines.slice(0, end === -1 ? lines.length : end); + const start = head.findIndex((line) => BADGE_LINE.test(line)); + const row = []; + for (let i = start; i >= 0 && i < head.length && BADGE_LINE.test(head[i]); i += 1) { + const [, alt, img, href] = head[i].match(BADGE_LINE); + row.push({ alt, img, href }); + } + return row; +} + +/** + * Turns the @strapi/strapi peer range into the floor shown on the badge, e.g. "^5.24.0" -> "5.24". + * + * @returns {string} The supported Strapi floor. + */ +function strapiFloor() { + const range = pkg.peerDependencies['@strapi/strapi']; + const match = range.match(/^(?:\^|~|>=)?\s*(\d+)\.(\d+)\.(\d+)/); + assert.ok(match, `unexpected @strapi/strapi peer range: ${range}`); + return match[3] === '0' ? `${match[1]}.${match[2]}` : `${match[1]}.${match[2]}.${match[3]}`; +} + +const shield = (text) => encodeURIComponent(text.replace(/-/g, '--').replace(/_/g, '__')); + +test('README starts with the six-badge row in the shared order', () => { + const row = badgeRow(); + assert.deepEqual( + row.map((badge) => badge.alt), + [ + 'npm version', + 'npm downloads', + 'CI', + `License: ${pkg.license}`, + `Strapi ${strapiFloor()}+`, + 'Docs', + ] + ); +}); + +test('every badge image and link is an absolute https URL', () => { + for (const { alt, img, href } of badgeRow()) { + assert.match(img, /^https:\/\/img\.shields\.io\//, `${alt}: image must be a shields.io URL`); + assert.match(href, /^https:\/\//, `${alt}: link must be absolute`); + } +}); + +test('npm badges point at this package', () => { + const [version, downloads] = badgeRow(); + const page = `https://www.npmjs.com/package/${pkg.name}`; + assert.equal(version.img, `https://img.shields.io/npm/v/${pkg.name}.svg`); + assert.equal(version.href, page); + assert.equal(downloads.img, `https://img.shields.io/npm/dm/${pkg.name}.svg`); + assert.equal(downloads.href, page); +}); + +test('CI badge shows a workflow that runs on main', () => { + const ci = badgeRow()[2]; + assert.equal( + ci.img, + `https://img.shields.io/github/actions/workflow/status/${slug}/${WORKFLOW}?branch=main&label=CI&logo=github` + ); + assert.equal( + ci.href, + `https://github.com/${slug}/actions/workflows/${WORKFLOW}?query=branch%3Amain` + ); + const workflow = read(path.join('.github/workflows', WORKFLOW)); + assert.match(workflow, /^\s+push:/m, `${WORKFLOW} must run on push`); + assert.doesNotMatch( + workflow, + /branches-ignore:\s*\n\s*-\s*main\b/, + `${WORKFLOW} must run on main` + ); +}); + +test('license badge matches package.json and links to the LICENSE file', () => { + const license = badgeRow()[3]; + assert.equal(license.img, `https://img.shields.io/badge/License-${shield(pkg.license)}-blue.svg`); + assert.equal(license.href, `https://github.com/${slug}/blob/main/LICENSE`); + assert.ok(existsSync(path.join(root, 'LICENSE')), 'LICENSE file is missing'); +}); + +test('Strapi badge states the @strapi/strapi peer floor and links to the compatibility section', () => { + const strapi = badgeRow()[4]; + assert.equal( + strapi.img, + `https://img.shields.io/badge/Strapi-${shield(`${strapiFloor()}+`)}-4945FF.svg` + ); + assert.equal(strapi.href, `https://github.com/${slug}#${COMPAT_ANCHOR}`); + const headings = readme + .split('\n') + .filter((line) => /^#{2,3} /.test(line)) + .map((line) => + line + .replace(/^#+ /, '') + .trim() + .toLowerCase() + .replace(/[^\w\- ]/g, '') + .replace(/ /g, '-') + ); + assert.ok(headings.includes(COMPAT_ANCHOR), `README has no "${COMPAT_ANCHOR}" heading`); +}); + +test('docs badge links to the project site', () => { + const docs = badgeRow()[5]; + assert.equal(docs.img, 'https://img.shields.io/badge/docs-project%20site-6d4aff.svg'); + assert.equal(docs.href, pkg.homepage); + assert.match(pkg.homepage, /^https:\/\/[\w-]+\.github\.io\/[\w-]+\/$/); +}); + +test('Pages hero shows the same badge row as the README', () => { + const html = read('docs/site/index.html'); + const block = html.match(/

]*>([\s\S]*?)<\/p>/); + assert.ok(block, 'docs/site/index.html has no shields row'); + const unescape = (value) => value.replace(/&/g, '&'); + const site = [ + ...block[1].matchAll(/\s* ({ alt, img: unescape(img), href: unescape(href) })); + assert.deepEqual(site, badgeRow()); +}); From 6c6b656fe90756b0580c69c57b7d5d4275f2e0a9 Mon Sep 17 00:00:00 2001 From: "Schero D." Date: Tue, 17 Nov 2026 22:40:02 +0100 Subject: [PATCH 3/4] docs(readme): descriptive alt text for the CI and docs badges Co-Authored-By: Claude Opus 5.5 --- README.md | 4 ++-- docs/site/index.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 37f6c30..5f7c4c6 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,10 @@ to external servers. [![npm version](https://img.shields.io/npm/v/strapi-plugin-magic-mark.svg)](https://www.npmjs.com/package/strapi-plugin-magic-mark) [![npm downloads](https://img.shields.io/npm/dm/strapi-plugin-magic-mark.svg)](https://www.npmjs.com/package/strapi-plugin-magic-mark) -[![CI](https://img.shields.io/github/actions/workflow/status/Schero94/Magicmark/test.yml?branch=main&label=CI&logo=github)](https://github.com/Schero94/Magicmark/actions/workflows/test.yml?query=branch%3Amain) +[![CI build status](https://img.shields.io/github/actions/workflow/status/Schero94/Magicmark/test.yml?branch=main&label=CI&logo=github)](https://github.com/Schero94/Magicmark/actions/workflows/test.yml?query=branch%3Amain) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/Schero94/Magicmark/blob/main/LICENSE) [![Strapi 5.57+](https://img.shields.io/badge/Strapi-5.57%2B-4945FF.svg)](https://github.com/Schero94/Magicmark#compatibility) -[![Docs](https://img.shields.io/badge/docs-project%20site-6d4aff.svg)](https://schero94.github.io/Magicmark/) +[![Documentation site](https://img.shields.io/badge/docs-project%20site-6d4aff.svg)](https://schero94.github.io/Magicmark/) Website: [schero94.github.io/Magicmark](https://schero94.github.io/Magicmark/) · npm: [strapi-plugin-magic-mark](https://www.npmjs.com/package/strapi-plugin-magic-mark) · diff --git a/docs/site/index.html b/docs/site/index.html index ad69328..379eb61 100644 --- a/docs/site/index.html +++ b/docs/site/index.html @@ -113,7 +113,7 @@

Save the view. Open it again with one click.

href="https://github.com/Schero94/Magicmark/actions/workflows/test.yml?query=branch%3Amain" >CI Save the view. Open it again with one click. Docs

From b7e17ae9c779aba3c06bb6b6547afbfeaaf1223a Mon Sep 17 00:00:00 2001 From: "Schero D." Date: Tue, 17 Nov 2026 22:40:02 +0100 Subject: [PATCH 4/4] test: expect the descriptive badge alt text Co-Authored-By: Claude Opus 5.5 --- tests/readme-badges.test.cjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/readme-badges.test.cjs b/tests/readme-badges.test.cjs index fc011ea..1a78bc0 100644 --- a/tests/readme-badges.test.cjs +++ b/tests/readme-badges.test.cjs @@ -63,10 +63,10 @@ test('README starts with the six-badge row in the shared order', () => { [ 'npm version', 'npm downloads', - 'CI', + 'CI build status', `License: ${pkg.license}`, `Strapi ${strapiFloor()}+`, - 'Docs', + 'Documentation site', ] ); });