Skip to content

Commit

Permalink
feat: documentation versions config to versions.json
Browse files Browse the repository at this point in the history
  • Loading branch information
timwessman committed Oct 25, 2024
1 parent 11b179d commit d6067a5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
30 changes: 12 additions & 18 deletions site/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
require("dotenv").config({
path: `.env.${process.env.NODE_ENV}`,
})
const latestVersion = process.env.npm_package_version;
const versionsFromGit = require('./src/data/versions.json').filter(v => v !== latestVersion);
const gitSources = versionsFromGit.map(version => ({
resolve: 'gatsby-source-git',
options: {
name: `docs-release-${version}`,
remote: `https://github.com/City-of-Helsinki/helsinki-design-system`,
branch: `release-${version}`,
patterns: 'site/src/docs/**',
},
}));

module.exports = {
pathPrefix: process.env.PATH_PREFIX,
Expand Down Expand Up @@ -150,24 +161,7 @@ module.exports = {
path: `${__dirname}/src/docs`,
},
},
{
resolve: `gatsby-source-git`,
options: {
name: `docs-release-3.9.0`,
remote: `https://github.com/City-of-Helsinki/helsinki-design-system`,
branch: `release-3.9.0`,
patterns: `site/src/docs/**`,
},
},
{
resolve: `gatsby-source-git`,
options: {
name: `docs-release-3.0.0`,
remote: `https://github.com/City-of-Helsinki/helsinki-design-system`,
branch: `release-3.0.0`,
patterns: `site/src/docs/**`,
},
},
...gitSources,
{
resolve: `gatsby-plugin-mdx`,
options: {
Expand Down
2 changes: 1 addition & 1 deletion site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "site",
"private": true,
"description": "Documentation for Helsinki Design System",
"version": "3.10.1",
"version": "4.0.0",
"workspaces": {
"nohoist": [
"gatsby",
Expand Down
22 changes: 12 additions & 10 deletions site/src/components/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import InternalLink from './InternalLink';
import ExternalLink from './ExternalLink';
import AnchorLink from './AnchorLink';
import './layout.scss';
import versions from '../data/versions.json';

const classNames = (...args) => args.filter((e) => e).join(' ');

Expand Down Expand Up @@ -124,6 +125,8 @@ const isMatchingParentLink = (link, slug) => {
const Layout = ({ location, children, pageContext }) => {
const pathParts = location.pathname.split('/');
const version = pathParts[1].startsWith('release-') ? pathParts[1] : undefined;
const locationWithoutVersion = hrefWithoutVersion(location.pathname, version);
const versionLabel = version ? `Version ${version.replace('release-', '')}` : `Version ${versions[0]}`;

// Some hrefs of internal links can't be replaced with MDXProvider's replace component logic.
// this code will take care of those
Expand Down Expand Up @@ -248,16 +251,15 @@ const Layout = ({ location, children, pageContext }) => {
logoAriaLabel="City of Helsinki Logo"
logo={<Logo src={logoFi} alt="Helsingin kaupunki" />}
>
<Header.ActionBarItem label={version} fixedRightPosition>
<Header.ActionBarSubItem label="latest" href={hrefWithoutVersion(location.pathname, version)} />
<Header.ActionBarSubItem
label="release-3.9.0"
href={hrefWithVersion(hrefWithoutVersion(location.pathname, version), 'release-3.9.0')}
/>
<Header.ActionBarSubItem
label="release-3.0.0"
href={hrefWithVersion(hrefWithoutVersion(location.pathname, version), 'release-3.0.0')}
/>
<Header.ActionBarItem label={versionLabel} fixedRightPosition>
{versions.map((versionNumber, index) => (
<Header.ActionBarSubItem
label={`Version ${versionNumber}`}
href={index > 0
? hrefWithVersion(locationWithoutVersion, `release-${versionNumber}`)
: locationWithoutVersion}
/>
))}
</Header.ActionBarItem>
</Header.ActionBar>
<Header.NavigationMenu>
Expand Down
5 changes: 5 additions & 0 deletions site/src/data/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
"4.0.0",
"3.10.2",
"3.0.0"
]

0 comments on commit d6067a5

Please sign in to comment.