Skip to content
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

[repo] Show a warning for stable versions that newer docs are available. #1219

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nextVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
* along with Moodle. If not, see <http://www.gnu.org/licenses/>.
*/

const latestVersion = '4.5';
const nextVersion = '5.0';
const nextLTSVersion = '5.3';
const nextVersionRoot = `/docs/${nextVersion}`;

module.exports = {
latestVersion,
nextVersion,
nextLTSVersion,
nextVersionRoot,
Expand Down
1 change: 1 addition & 0 deletions src/theme/MoodlePageBanner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function MoodlePageBanner({ frontMatter, metadata = {} }) {
/>
<UnsupportedVersionBanner
frontMatter={frontMatter}
metadata={metadata}
/>
</>
);
Expand Down
84 changes: 78 additions & 6 deletions src/theme/UnsupportedVersionBanner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ import Translate from '@docusaurus/Translate';
import AutoFixHighIcon from '@mui/icons-material/AutoFixHigh';
import Admonition from '@theme/Admonition';
import { getReleaseStatus, getVersion } from '@site/src/utils/SupportedReleases';
import {
useActivePlugin,
useDocVersionSuggestions,
} from '@docusaurus/plugin-content-docs/client';

const getVersionMainDoc = (version) => version.docs.find((doc) => doc.id === version.mainDocId);

function UnsupportedTitle() {
return (
Expand Down Expand Up @@ -93,6 +99,34 @@ function GeneralSupportExpiredWarning({ versionData }) {
);
}

function NewerVersionAvailableWarning({ versionData }) {
const { pluginId } = useActivePlugin({ failfast: true });
const { latestDocSuggestion, latestVersionSuggestion } = useDocVersionSuggestions(pluginId);
const latestVersionSuggestedDoc = latestDocSuggestion ?? getVersionMainDoc(latestVersionSuggestion);

return (
<Admonition
type="caution"
icon={
<AutoFixHighIcon fontSize="inherit" />
}
title="Newer Version Available"
>
<strong>
This documentation is for Moodle
{' '}
{versionData.name}
.
</strong>
<br />
You may also want to read the documentation for the
{' '}
<Link to={latestVersionSuggestedDoc.path}>upcoming version of Moodle</Link>
.
</Admonition>
);
}

function FutureReleaseWarning({ versionData }) {
return (
<Admonition
Expand Down Expand Up @@ -162,23 +196,45 @@ function ExperimentalWarning() {
);
}

function VersionedSupportWarning({ versionData, moodleVersion }) {
function VersionedSupportWarning({ versionData, moodleVersion, metadata }) {
const releaseStatus = getReleaseStatus(versionData, moodleVersion);
const { sidebar } = metadata;

// Versions fit the following categories:
// - Experimental (show danger warning)
// - Current version (released or `main` branch)
// - main branch (no warning)
// - stable version information (no warning)
// - stable versioned docs (indicate main branch information is available)
// - Security Only (show warning)
// - Future (show warning)
// - Future Stable (show warning)
// - Unsupported (show danger warning)

if (versionData.isExperimental) {
// Experimental version.
// Experimental versions trump all.
// Always show this notice.
return (
<ExperimentalWarning versionData={versionData} />
);
}

if (sidebar === 'docs' && moodleVersion.version !== 'current' && metadata.slug !== '/') {
// This is a versioned doc page but it's not the 'current' version (main branch).
// Show a warning banner that that there are docs for the 'main' branch.
return (
<NewerVersionAvailableWarning versionData={versionData} />
);
}

if (releaseStatus === 'current') {
// Still in general support.
// This documentation is for docs still in general support.
return null;
}

if (releaseStatus === 'future' || releaseStatus === 'future-stable') {
// Not yet supported.
// This documentatino relates to a versino of Moodle which has yet to be released.
// This is probably a version about to be released.
// TODO Add a warning banner.
return (
<FutureReleaseWarning versionData={versionData} />
Expand All @@ -197,8 +253,21 @@ function VersionedSupportWarning({ versionData, moodleVersion }) {
);
}

export default function VersionInfo({ frontMatter }) {
const { moodleVersion = null } = frontMatter;
const guessMoodleVersion = (frontMatter, metadata) => {
if (frontMatter.moodleVersion) {
return frontMatter.moodleVersion;
}

if (metadata.version) {
if (metadata.version.match(/^(?<seriesMajor>\d+\.\d+)(?<minor>\.\d+)?/)) {
return metadata.version;
}
}
return undefined;
};

export default function VersionInfo({ frontMatter, metadata = {} }) {
const moodleVersion = guessMoodleVersion(frontMatter, metadata);

if (!moodleVersion) {
// No version number found.
Expand All @@ -208,13 +277,16 @@ export default function VersionInfo({ frontMatter }) {
const versionData = getVersion(moodleVersion);
if (!versionData) {
// No valid version data found.
// We don't know how to handle this version.
return null;
}

return (
<VersionedSupportWarning
versionData={versionData}
moodleVersion={moodleVersion}
metadata={metadata}
sidebar={metadata?.sidebar}
/>
);
}
Loading