Skip to content

feat: add Copy page and View buttons on guide pages#22

Open
Zodiarche wants to merge 4 commits into
mainfrom
feat/copy-markdown-button
Open

feat: add Copy page and View buttons on guide pages#22
Zodiarche wants to merge 4 commits into
mainfrom
feat/copy-markdown-button

Conversation

@Zodiarche

@Zodiarche Zodiarche commented May 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add two compact buttons in the top-right of every guide page:

  • Copy page — fetches the raw markdown for the current URL and writes it to the clipboard. Briefly switches to "Copied!" as feedback.
  • View — opens the raw markdown in a new tab.

A custom Docusaurus plugin (plugins/raw-markdown.js) writes a clean .md file (frontmatter stripped) for every doc into the build output at the same URL path as the rendered page, in both locales:

  • /psdk/battle-engine/how-to-create-a-weather.md (English source)
  • /fr/psdk/battle-engine/creer-une-meteo-et-ses-effets.md (French translation with its localized slug)

The buttons only render on guide pages — not on the homepage, not on auto-generated category index pages — by checking metadata.sourceDirName in the swizzled DocItem/Layout.

Picked over the existing docusaurus-markdown-source-plugin (briefly tried) because that one ships a hardcoded "Open Markdown" dropdown on every doc page including the home, with no config to disable the UI or scope it to guides.

Related issues

Closes #19

Test plan

  • bun run typecheck passes
  • bun run build passes (both locales) — plugin reports [raw-markdown] en: copied 46 markdown files and same for fr
  • Headless Chrome verification:
    • EN guide page: buttons visible, View link → /psdk/battle-engine/how-to-create-a-weather.md
    • FR guide page: buttons visible, View link → /fr/psdk/battle-engine/creer-une-meteo-et-ses-effets.md (localized slug) ✓
    • EN home, FR home, category index: no buttons ✓
  • <page>.md URL fetch returns the raw markdown (frontmatter stripped) with status 200, in both locales
  • Click "Copy page" in a real browser, paste in an editor → markdown matches the page (manual verification recommended; the headless test couldn't read the clipboard due to focus/permission quirks but the underlying API is correct)

Screenshots

@Zodiarche Zodiarche self-assigned this May 10, 2026
Comment thread plugins/raw-markdown.js Outdated
Comment thread plugins/raw-markdown.js Outdated
Add a small set of two buttons in the top-right of each guide article:
- Copy page: fetches the raw markdown for the current URL and writes it
  to the clipboard (briefly switches to 'Copied!' as feedback).
- View: opens the raw markdown in a new tab.

A custom Docusaurus plugin (plugins/raw-markdown.js) writes a clean
.md file (frontmatter stripped) for every doc into the build output at
the same URL path as the rendered page, in both locales:
  /psdk/battle-engine/how-to-create-a-weather.md (English source)
  /fr/psdk/battle-engine/creer-une-meteo-et-ses-effets.md (French
  translation, with its localized slug).

The buttons only render on guide pages — not on the homepage and not on
auto-generated category index pages — by checking metadata.sourceDirName
in the swizzled DocItem/Layout.

Closes #19
Add Biome 2.4.16 as the linter/formatter for the TS/JS/CSS layer, with
lineEnding set to lf. Provides bun run lint/format/check scripts. Format the
files touched by this PR; a full-repo format and CI gate are left as a
follow-up.
Replace the frontmatter regex with startsWith/indexOf/slice (assuming LF, now
enforced via .gitattributes), and replace the manual stack-based directory walk
with fs.globSync plus a small toUrlPath helper. Addresses review feedback on
plugins/raw-markdown.js.
@Zodiarche Zodiarche force-pushed the feat/copy-markdown-button branch from 95691f4 to c9b013e Compare June 11, 2026 16:58
@Zodiarche Zodiarche requested a review from NuriYuri June 11, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a "Copy as markdown" button on every doc page

2 participants