-
Notifications
You must be signed in to change notification settings - Fork 61
feat(docs): added links to github changelog to migration page headers #3604
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
base: main
Are you sure you want to change the base?
Changes from all commits
597e547
42c9b11
bb95dfd
3f7ab74
c8e5fe1
481e361
1254a6b
db30c8a
733251e
4cafce8
0ee97de
e466a11
fea4901
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import type { Root } from 'hast' | ||
| import type { Plugin } from 'unified' | ||
| import { SKIP, visit } from 'unist-util-visit' | ||
| import { getHeadingSlug, isHeading } from './utils' | ||
|
|
||
| // A rehype plugin to apply CSS classes to tables rendered in markdown (or MDX) files when wrapped in a `<BsTable />` | ||
| // component. | ||
|
|
@@ -32,3 +33,47 @@ export const rehypeBsTable: Plugin<[], Root> = function () { | |
| }) | ||
| } | ||
| } | ||
|
|
||
| // A rehype plugin to reorder header anchor link and header text | ||
| export const rehypeHeaderLinksOrder: Plugin<[], Root> = function () { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I quite don't unserstand why we do want them in this exact order, I think title -> Full changelog -> anchor is fine no ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I don't reorder them, the DOM will not reflect the reading/display order, and keyboard navigation won't match what the user sees : We will see title -> anchor -> full changelog, and keyboard navigation order will be title -> full changelog -> anchor. |
||
| return function rehypeHeaderLinksOrderPlugin(ast) { | ||
| visit(ast, 'element', (node, index, parent) => { | ||
| if (!isHeading(node.tagName) || !parent) { | ||
| return | ||
| } | ||
|
|
||
| const hasAnchorClass = (child: any) => { | ||
| const childClass = child?.properties?.class | ||
| if (typeof childClass === 'string') { | ||
| return childClass.includes('anchor-link') | ||
| } | ||
|
|
||
| if (Array.isArray(childClass)) { | ||
| return childClass.some(item => String(item).includes('anchor-link')) | ||
| } | ||
|
|
||
| return false | ||
| } | ||
|
|
||
| const hasAnchor = hasAnchorClass(node.children[0]) | ||
| const headingIndex = node.children.findIndex(child => child.type === 'text') | ||
| if (!hasAnchor || headingIndex === -1) { | ||
| return | ||
| } | ||
|
|
||
| const [anchorLink] = node.children.splice(0, 1) | ||
| node.children.splice(headingIndex, 0, anchorLink) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // A rehype plugin to generate correct heading id | ||
| export const rehypeCustomHeaderSlug: Plugin<[], Root> = function () { | ||
| return function rehypeCustomHeaderSlugPlugin(ast) { | ||
| visit(ast, 'element', (node) => { | ||
| if (/^h[1-6]$/.test(node.tagName) && node?.properties?.id && typeof node.properties.id === 'string') { | ||
| node.properties = { ...node.properties, id: getHeadingSlug(node.properties.id) } | ||
| } | ||
| }) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import toString from 'mdast-util-to-string' | |
| import { remark } from 'remark' | ||
| import remarkHtml from 'remark-html' | ||
| import { getVersionedDocsPath } from './path' | ||
| import { getConfig } from './config' | ||
|
|
||
| export function capitalizeFirstLetter(str: string) { | ||
| return str.charAt(0).toUpperCase() + str.slice(1) | ||
|
|
@@ -30,6 +31,10 @@ export function getSlug(str: string) { | |
| return slug(str).replace(/--+/g, '-') | ||
| } | ||
|
|
||
| export function getHeadingSlug(str: string) { | ||
| return str.replace(/-------full-changelog---------------------/g, '') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't figure out why we have this specific string ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I understand, rehypeHeadingIds generates slug from the content of the whole node, which includes the "full changelog" link, and generates this string. |
||
| } | ||
|
|
||
| export function trimLeadingAndTrailingSlashes(str: string) { | ||
| return str.replace(/^\/+|\/+$/g, '') | ||
| } | ||
|
|
@@ -47,3 +52,17 @@ export function processMarkdownToHtml(markdown: string): string { | |
| export function getComponentSVG(className: string): string { | ||
| return `<svg class="${className}" width="1rem" height="1rem" aria-label=" - component type - "><use xlink:href="${getVersionedDocsPath('assets/img/ouds-web-sprite.svg#component-atom')}" /></svg>` | ||
| } | ||
|
|
||
| export function getVersionLink(version: string): string { | ||
| return `<a class="link icon-link float-end p-none" href="https://github.com/Orange-OpenSource/Orange-Boosted-Bootstrap/releases/tag/${version}-ouds-web" target="_blank" rel="noopener"> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a big fan of using float-end, but can't figure out how to achieve the smae thing in a different way. |
||
| Full changelog | ||
| <svg class="m-none ms-xsmall" aria-hidden="true"> | ||
| <use xlink:href="${getVersionedDocsPath('assets/img/ouds-web-sprite.svg#external-link')}"/> | ||
| </svg> | ||
| </a>` | ||
| } | ||
|
|
||
| export function isHeading(tag: string): boolean { | ||
| const headingsRangeRegex = new RegExp(`^h[${getConfig().anchors.min}-${getConfig().anchors.max}]$`) | ||
| return !!tag.match(headingsRangeRegex) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.