diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index db7b269e..f2e05359 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,6 +9,7 @@ Each documentation page is built from an MDX file. Each file starts with YAML fr - `sidebar_label`: the label that's shown in the side navigation. - `sidebar_position`: the position of this page within its section in the side navigation. - `slug`: used to maintain URLs from the previous documentation platform. Don't add a slug for new pages, or edit existing slugs. +- `hide_in_snapshot: true`: makes the page [unlisted](https://docusaurus.io/docs/create-doc#unlisted) in the unreleased snapshot version. An unlisted page is hidden from the side navigation, search engines, and the sitemap, and it stays reachable by its URL. The key has no effect in releases. The dev server shows the page in the side navigation, with an "Unlisted page" banner. - `enterprise: true`, `beta: true`, or `experimental: true`: shows a badge at the top of the page. The `enterprise` and `beta` badges also show next to the page in the side navigation. Pages in `cloud/` and `tutorials/` can also have `cloud_title`, `cloud_tags`, and `cloud_order` keys. The Hazelcast Cloud console reads them. Do not remove or rename them. diff --git a/docusaurus.config.ts b/docusaurus.config.ts index 7389b93f..8894d9f7 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -2,7 +2,7 @@ import {themes as prismThemes} from 'prism-react-renderer'; import type {Config} from '@docusaurus/types'; import type * as Preset from '@docusaurus/preset-classic'; import {redirects} from './src/redirects'; -import {docs, versionedDocs, versionedInstances, latestSegs, canonicalSitemapItems} from './src/docsPlugins'; +import {docs, versionedDocs, versionedInstances, latestSegs, canonicalSitemapItems, parseFrontMatter} from './src/docsPlugins'; import {variables, versionedVariables} from './src/variables'; // Retired versions served as static Antora HTML from a separate site. See plugins/archived-versions. @@ -48,6 +48,7 @@ const config: Config = { onBrokenAnchors: 'warn', markdown: { + parseFrontMatter, hooks: { onBrokenMarkdownLinks: 'throw', onBrokenMarkdownImages: 'throw', diff --git a/hazelcast/install-and-upgrade/community-edition/community.mdx b/hazelcast/install-and-upgrade/community-edition/community.mdx index a16e49d9..b0c63620 100644 --- a/hazelcast/install-and-upgrade/community-edition/community.mdx +++ b/hazelcast/install-and-upgrade/community-edition/community.mdx @@ -3,6 +3,7 @@ title: "Community Edition Release Notes" sidebar_label: "Release Notes" sidebar_position: 1 slug: /release-notes/community +hide_in_snapshot: true --- :::important diff --git a/hazelcast/install-and-upgrade/enterprise-edition/enterprise.mdx b/hazelcast/install-and-upgrade/enterprise-edition/enterprise.mdx index c7ad974f..d8ff94a4 100644 --- a/hazelcast/install-and-upgrade/enterprise-edition/enterprise.mdx +++ b/hazelcast/install-and-upgrade/enterprise-edition/enterprise.mdx @@ -4,6 +4,7 @@ sidebar_label: "Release Notes" sidebar_position: 1 slug: /release-notes/enterprise enterprise: true +hide_in_snapshot: true --- :::important diff --git a/hazelcast/install-and-upgrade/releases.mdx b/hazelcast/install-and-upgrade/releases.mdx index 22abb60f..50cbf602 100644 --- a/hazelcast/install-and-upgrade/releases.mdx +++ b/hazelcast/install-and-upgrade/releases.mdx @@ -3,6 +3,7 @@ title: "Hazelcast Platform release notes" sidebar_label: "Release Notes" sidebar_position: 2 slug: /release-notes/releases +hide_in_snapshot: true --- :::important diff --git a/management-center/install-and-upgrade/release-notes.mdx b/management-center/install-and-upgrade/release-notes.mdx index 37f5909b..c02c579b 100644 --- a/management-center/install-and-upgrade/release-notes.mdx +++ b/management-center/install-and-upgrade/release-notes.mdx @@ -2,6 +2,7 @@ title: "Release Notes" sidebar_position: 3 slug: /release-notes/release-notes +hide_in_snapshot: true --- These release notes list any new features, enhancements, fixes, security issues and breaking changes that were made for Hazelcast Management Center. diff --git a/operator/get-started/release-notes.mdx b/operator/get-started/release-notes.mdx index 88f52b16..e6418687 100644 --- a/operator/get-started/release-notes.mdx +++ b/operator/get-started/release-notes.mdx @@ -2,6 +2,7 @@ title: "Release notes" sidebar_position: 3 slug: /release-notes +hide_in_snapshot: true --- These release notes list any new features, enhancements, fixes, and breaking changes implemented between version 5.19.0 and version 5.20.0 of Hazelcast Platform Operator. diff --git a/src/docsPlugins.ts b/src/docsPlugins.ts index 9f142151..1bf4ba47 100644 --- a/src/docsPlugins.ts +++ b/src/docsPlugins.ts @@ -6,7 +6,7 @@ // _versioned_sidebars/ sidebar stubs, gitignored (see ensureVersionedSidebars) import fs from 'fs'; import path from 'path'; -import type {PluginConfig} from '@docusaurus/types'; +import type {ParseFrontMatter, PluginConfig} from '@docusaurus/types'; import type {Options} from '@docusaurus/plugin-content-docs'; import latestLinks, {type LatestSegs} from './remark/latestLinks'; import headingVariables from './remark/headingVariables'; @@ -48,6 +48,17 @@ export function canonicalSitemapItems(items: T[]): T[] }); } +// `markdown.parseFrontMatter` hook: a page with `hide_in_snapshot: true` in a component's unreleased snapshot becomes `unlisted`. +// The release script copies frontmatter into each release, so writing `unlisted` in the file would hide the page in releases too. +export const parseFrontMatter: ParseFrontMatter = async (params) => { + const result = await params.defaultParseFrontMatter(params); + const [id] = path.relative(siteDir, params.filePath).split(path.sep); + if (result.frontMatter.hide_in_snapshot === true && id !== undefined && id in snapshotSegs) { + result.frontMatter.unlisted = true; + } + return result; +}; + // `caution`/`important` are not default Docusaurus admonition keywords; fidelity Layer 2 compares admonition types. const admonitions = {keywords: ['caution', 'important'], extendDefaults: true}; diff --git a/src/test/docsPlugins.test.js b/src/test/docsPlugins.test.js index 776f0384..f0a925a9 100644 --- a/src/test/docsPlugins.test.js +++ b/src/test/docsPlugins.test.js @@ -120,6 +120,21 @@ test('a category takes the badge of its landing page, nested items are tagged, a assert.equal(noLanding.items[0].className, 'nav-badge-beta') }) +test('hide_in_snapshot makes a page unlisted in an unreleased snapshot only', async () => { + const unlisted = async (file, frontMatter = {hide_in_snapshot: true}) => { + const {frontMatter: parsed} = await docsPlugins.parseFrontMatter({ + filePath: path.join(site, file), + fileContent: '', + defaultParseFrontMatter: async () => ({frontMatter: {...frontMatter}, content: ''}), + }) + return parsed.unlisted === true + } + assert.equal(await unlisted('hazelcast/page.mdx'), true, 'snapshot main') + assert.equal(await unlisted('hazelcast_versioned_docs/version-5.7/page.mdx'), false, 'release') + assert.equal(await unlisted('clc/page.mdx'), false, 'main that is the newest release') + assert.equal(await unlisted('hazelcast/page.mdx', {}), false, 'no flag') +}) + // Version names are dotted numbers, compared numerically: 5.10 is newer than 5.9. const compareVersions = (a, b) => { const pa = a.split('.').map(Number) diff --git a/src/theme/ContentVisibility/index.tsx b/src/theme/ContentVisibility/index.tsx new file mode 100644 index 00000000..efb9ef80 --- /dev/null +++ b/src/theme/ContentVisibility/index.tsx @@ -0,0 +1,15 @@ +import React, {type ReactNode} from 'react'; +import ContentVisibility from '@theme-original/ContentVisibility'; +import type ContentVisibilityType from '@theme/ContentVisibility'; +import type {WrapperProps} from '@docusaurus/types'; +import {UnlistedMetadata} from '@docusaurus/theme-common'; + +type Props = WrapperProps; + +// Shows the unlisted banner in development environments only +export default function ContentVisibilityWrapper(props: Props): ReactNode { + if (process.env.NODE_ENV === 'production') { + return props.metadata.unlisted ? : null; + } + return ; +}