diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 923776a..d879199 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -12,3 +12,6 @@ contact_links: - name: ⭐ Star on GitHub url: https://github.com/Schero94/Magic-Sessionmanager about: Show your support by starring the repository + - name: 🏢 Used by + url: https://schero94.github.io/Magic-Sessionmanager/#used-by + about: See the companies that use Magic Session Manager. To add yours, choose "Showcase your company" above. diff --git a/.github/ISSUE_TEMPLATE/showcase.yml b/.github/ISSUE_TEMPLATE/showcase.yml new file mode 100644 index 0000000..f4b75a5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/showcase.yml @@ -0,0 +1,58 @@ +name: 🏢 Showcase your company +description: Show your company's logo in the "Used by" section of the Magic Session Manager documentation site. +title: 'Showcase: ' +labels: ['showcase'] +body: + - type: markdown + attributes: + value: | + Thanks for using Magic Session Manager! This form lists your company in the **Used by** section of the [documentation site](https://schero94.github.io/Magic-Sessionmanager/#used-by) and in its `llms.txt`. + + - A maintainer reviews every request. After approval, a pull request adds your entry, and it appears on the site once that is merged. + - The link to your website carries `rel="ugc"`, as search engines ask for user-submitted links. + - Everything you enter here is public. Open an issue at any time to have the entry removed. + + - type: input + id: name + attributes: + label: Company name + description: "As it should appear on the site: 2 to 60 characters, letters, digits, spaces and & . , ' ( ) + ! - only." + placeholder: Example Co + validations: + required: true + + - type: input + id: website + attributes: + label: Website + description: The company's public website, starting with https:// + placeholder: https://www.example.com + validations: + required: true + + - type: textarea + id: logo + attributes: + label: Logo + description: Drag one PNG, JPEG or WebP file into this field (at most 500 KB, no SVG, no links to other sites). A wide logo on a transparent or white background works best; it is shown on a light tile at up to 320 x 160 pixels. + validations: + required: true + + - type: input + id: description + attributes: + label: How you use the plugin (optional) + description: One plain-text sentence, at most 140 characters, without links. + placeholder: Our editors use it every day in our customer portal. + + - type: checkboxes + id: permission + attributes: + label: Permission + options: + - label: I am authorised to represent this company and to allow use of its name and logo. + required: true + - label: The logo and name may be shown publicly on this site and in its llms.txt. + required: true + - label: Removal can be requested any time via an issue. + required: true diff --git a/.github/scripts/showcase.mjs b/.github/scripts/showcase.mjs new file mode 100644 index 0000000..7631999 --- /dev/null +++ b/.github/scripts/showcase.mjs @@ -0,0 +1,1316 @@ +#!/usr/bin/env node +/** + * "Used by" showcase for the plugin documentation site (docs/site). + * + * One dependency-free script, byte-identical in every plugin repository. The workflow + * `.github/workflows/showcase.yml` calls it when a maintainer labels a showcase issue, and the + * Pages workflow calls `render` before it uploads docs/site. `showcase.test.mjs` covers the + * parser, the validators, the logo checks and the renderer, including hostile input. + * + * Subcommands: + * - `prepare` reads the `issues` event payload as untrusted data, validates the form (name, + * website, logo, description, consent), downloads the logo from GitHub's attachment host only, + * checks it by magic bytes and pixel size and re-encodes it with sharp. It needs no write token + * and prints one JSON result (`add`, `remove` or `reject`) as a step output. + * - `apply` validates that result again, writes docs/site/showcase.json, the logo and the + * sitemap `lastmod`, and writes the commit message, pull request body or rejection comment. + * - `render` writes showcase.json into docs/site/index.html (static HTML and JSON-LD) and + * docs/site/llms.txt, so crawlers and language models see the list without JavaScript. + * + * sharp is optional: `SHOWCASE_SHARP_DIR` names a directory with an installed sharp (the + * workflow installs an exact version there and then requires it). Without sharp, a logo is kept + * as uploaded only when it is already small, static and within the stored size limits. + */ +import { Buffer } from 'node:buffer'; +import { + appendFileSync, + existsSync, + mkdirSync, + readFileSync, + rmSync, + writeFileSync, +} from 'node:fs'; +import { createRequire } from 'node:module'; +import path from 'node:path'; +import process from 'node:process'; +import { URL, pathToFileURL } from 'node:url'; +import { parseArgs } from 'node:util'; + +/** Issue labels used by the form and the workflow. */ +export const LABELS = Object.freeze({ + submit: 'showcase', + approve: 'showcase-approved', + remove: 'showcase-remove', +}); + +/** Headings of the issue form (`.github/ISSUE_TEMPLATE/showcase.yml`), in form order. */ +export const FORM_HEADINGS = Object.freeze({ + name: 'Company name', + website: 'Website', + logo: 'Logo', + description: 'How you use the plugin (optional)', + consent: 'Permission', +}); + +/** Checkbox labels of the form. All three must be ticked. */ +export const CONSENT_OPTIONS = Object.freeze([ + 'I am authorised to represent this company and to allow use of its name and logo.', + 'The logo and name may be shown publicly on this site and in its llms.txt.', + 'Removal can be requested any time via an issue.', +]); + +/** Size and length limits. */ +export const LIMITS = Object.freeze({ + bodyChars: 10000, + nameMin: 2, + nameMax: 60, + urlMax: 200, + descriptionMax: 140, + downloadBytes: 500 * 1024, + downloadTimeoutMs: 15000, + maxRedirects: 3, + inputPixels: 4096 * 4096, + inputMinSide: 16, + logoWidth: 320, + logoHeight: 160, + storedBytes: 64 * 1024, + storedMaxWidth: 640, + storedMaxHeight: 320, + slugMax: 40, +}); + +/** The only accepted logo URL: an image dropped into a GitHub issue form. */ +const ATTACHMENT_URL = + /^https:\/\/github\.com\/user-attachments\/assets\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/; + +/** Hosts that GitHub redirects attachment downloads to (checked on every redirect hop). */ +export const ATTACHMENT_REDIRECT_HOSTS = Object.freeze([ + 'github-production-user-asset-6210df.s3.amazonaws.com', + 'private-user-images.githubusercontent.com', + 'objects.githubusercontent.com', + 'user-images.githubusercontent.com', +]); + +/** Host suffixes that never belong to a public company website. */ +const BLOCKED_HOST_SUFFIXES = [ + 'localhost', + 'local', + 'internal', + 'intranet', + 'lan', + 'home', + 'corp', + 'private', + 'test', + 'invalid', + 'onion', + 'arpa', +]; + +const NAME_PATTERN = /^[\p{L}\p{N}][\p{L}\p{M}\p{N} &.,'’()+!-]*$/u; +const DESCRIPTION_PATTERN = /^[\p{L}\p{M}\p{N} .,;:!?'’"“”()&%+/-]*$/u; +const LOGO_PATH = /^showcase\/[a-z0-9-]{1,40}\.(?:webp|png|jpg)$/; +const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/; +const HTML_START = ''; +const HTML_END = ''; + +/** + * Error with a message that is safe to post on the issue. Messages never contain submitted text. + */ +export class ShowcaseError extends Error { + /** + * @param {string} message Reason shown to the submitter. + */ + constructor(message) { + super(message); + this.name = 'ShowcaseError'; + } +} + +/** + * Normalises a single-line text value: Unicode NFC, collapsed whitespace, trimmed. + * @param {string} value Raw value. + * @returns {string} Normalised value. + */ +const cleanText = (value) => value.normalize('NFC').replace(/\s+/g, ' ').trim(); + +/** + * Compares company names case-insensitively and independent of Unicode compatibility forms. + * @param {string} value Name. + * @returns {string} Comparison key. + */ +export const nameKey = (value) => + cleanText(String(value).normalize('NFKC')).toLocaleLowerCase('en'); + +/** + * Splits a GitHub issue-form body into its sections. The form renders every field as + * `###