Repository navigation
feat: ship a comark-linter config for sites #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0219d15
feat: ship a comark-linter config for sites
atinux 51b7a1d
docs: fix playground anchors broken by flat heading ids
atinux 65f403c
ci: lint playground content with the shipped config
atinux 00f631c
refactor: move Markdown components into app/components/prose
atinux 2c31a4e
feat: read lint components from the prose folders
atinux 32d70ed
refactor: pass Markdown components explicitly, not as globals
atinux 6c2afba
chore(deps): run comark-lint without -c through comark-linter 0.7.6
atinux 094d485
chore: install comark-linter releases without the release-age wait
atinux a411f43
perf: load each page's Markdown components only on that page
atinux 1d0110e
chore: drop the comark-linter release-age exclusion
atinux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // `::landing-hero` is Nuxt UI's page hero. | ||
| export { default } from '@nuxt/ui/components/PageHero.vue' |
2 changes: 1 addition & 1 deletion
2
app/components/landing/LandingHeroDemo.vue → ...nents/content/landing/LandingHeroDemo.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import type { Component } from 'vue' | ||
|
|
||
| /** | ||
| * Names the layer's Markdown components after their file: `content/CodeExplorer.vue` renders | ||
| * `::code-explorer`. Each page globs its own folder (docs pages `content/`, the landing page | ||
| * `content/landing/`) and passes the result to `MarkdownDocument`, so none is global and neither | ||
| * page loads the other's, such as the landing demo's Markdown parser. `lint.mjs` reads both folders. | ||
| */ | ||
| export function byFileName(modules: Record<string, unknown>): Record<string, Component> { | ||
| return Object.fromEntries( | ||
| Object.entries(modules).map(([path, component]) => [path.slice(path.lastIndexOf('/') + 1).replace(/\.\w+$/, ''), component as Component]), | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // @ts-check | ||
| // A comark-linter config for sites extending this layer. Run `comark-lint` from the site's root: | ||
| // comark-lint "content/**/*.md" | ||
| // next to a `comark-lint.config.ts` that re-exports it: `export { default } from 'comark-docs/lint.mjs'`. | ||
| // Plain JavaScript, since Node won't strip types from a file in node_modules. | ||
| import { readdirSync } from 'node:fs' | ||
| import { basename, dirname } from 'node:path' | ||
| import { fileURLToPath } from 'node:url' | ||
| import { comarkContent } from 'comark-content' | ||
| import fs from 'comark-content/sources/fs' | ||
| import emoji from 'comark/plugins/emoji' | ||
|
|
||
| const kebab = (/** @type {string} */ name) => name.replace(/[A-Z]/g, (c, i) => (i ? '-' : '') + c.toLowerCase()) | ||
|
|
||
| /** The kebab-case names of the components in a folder and its subfolders. */ | ||
| function componentsIn(/** @type {string} */ dir) { | ||
| return readdirSync(dir, { recursive: true, encoding: 'utf8' }) | ||
| .map(file => basename(file).match(/^(\w+)\.(vue|ts)$/)?.[1]) | ||
| .filter(name => name !== undefined) | ||
| .map(name => kebab(name)) | ||
| } | ||
|
|
||
| const nuxtUi = dirname(fileURLToPath(import.meta.resolve('@nuxt/ui/components/Button.vue'))) | ||
|
|
||
| // What the pages pass to `MarkdownDocument`: Nuxt UI's prose components and the layer's | ||
| // `app/components/content/`, plus every Nuxt UI component with the `u-` prefix, such as `::u-button`. | ||
| const components = [ | ||
| ...componentsIn(`${nuxtUi}/prose`), | ||
| ...componentsIn(fileURLToPath(new URL('app/components/content', import.meta.url))), | ||
| ...readdirSync(nuxtUi).filter(file => file.endsWith('.vue')).map(file => `u-${kebab(basename(file, '.vue'))}`), | ||
| ] | ||
|
|
||
| // Each page's URL, mapped to its file the way comark-content derives the URL from it. | ||
| const pages = new Map() | ||
| for (const item of await comarkContent({ source: fs('content') }).list()) { | ||
| pages.set(item.path, `content/${item.meta.stem}${item.meta.extension}`) | ||
| } | ||
|
|
||
| /** @type {import('comark-linter').Config} */ | ||
| export default { | ||
| components, | ||
| // The layer parses `:smile:` shortcodes as emoji, not as inline components. | ||
| plugins: [emoji()], | ||
| links: { | ||
| // Guides link a local dev server on purpose, for readers running it. | ||
| skip: ['localhost'], | ||
| routes: path => pages.get(path.replace(/\/$/, '') || '/'), | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // Lints this playground with the config the layer ships to sites. | ||
| export { default } from '../lint.mjs' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.