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

feat HDS 2352 enable versioned documentation #1349

Merged
merged 25 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c1abbf9
feat: support git as a gatsby documentation source
timwessman Sep 4, 2024
ff7b4c9
clean up the code
timwessman Sep 5, 2024
176e968
fix: package version bug
timwessman Oct 9, 2024
5decc1b
fix: webpack chunking problems
timwessman Oct 10, 2024
72bd646
fix: reroute some special links on multiversion documentation
timwessman Oct 17, 2024
abeaa43
fix: package and yarn.lock fix
timwessman Oct 17, 2024
5da2d73
fix: check links always after location change
timwessman Oct 18, 2024
908e023
feat: documentation versions config to versions.json
timwessman Oct 18, 2024
ed0f574
fix: dependency update
timwessman Oct 22, 2024
fa4a95a
debug on test server
timwessman Nov 5, 2024
2517e0e
more debug on test server
timwessman Nov 5, 2024
e946ec7
fix: new approach to versioned urls
timwessman Nov 6, 2024
f21c584
debug
timwessman Nov 7, 2024
cb276f1
fix: try to avoid double prefix
timwessman Nov 7, 2024
18befea
fix: navigation links
timwessman Nov 11, 2024
bd70258
remove console logs
timwessman Nov 11, 2024
4f56d05
test versions
timwessman Nov 11, 2024
cfec2bb
Test just latest versions
timwessman Nov 12, 2024
0ceb0d7
test without prefix for navigation
timwessman Nov 13, 2024
127a235
fix: spotted broken pages
timwessman Nov 13, 2024
05b9850
feat: Selected -style for ActionBarSubItem
timwessman Nov 14, 2024
1510fa3
fix: site home page layout, wrong navigation items
timwessman Nov 15, 2024
0ca805a
fix: use old hds correctly with old documentation, removed webpack sp…
timwessman Nov 15, 2024
a928814
feat: add to changelog. Remove commmented out code
timwessman Nov 18, 2024
afa8cb0
fix: docs home page style fix
timwessman Nov 20, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ Changes that are not related to specific components

#### Added

- Documentation of older versions (3.11 & 2.17) of HDS is also available on the documentation site.
- [StatusLabel] Documentation about SCSS usage.
- [Breadcrumbs] Documentation about SCSS usage.
- [Checkbox] Documentation about SCSS usage.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions packages/react/src/components/header/Header.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -761,3 +761,38 @@ export const WithUserMenu = (args: HeaderProps) => {
</>
);
};

export const WithCustomMenu = (args: HeaderProps) => {
const lang = 'fi';
const I18n = translations[lang];
const versions = ['Version 4.0.0', 'Version 3.11.0', 'Version 2.17.1'];
const selectedVersion = 'Version 3.11.0';

return (
<>
<Header {...args}>
<Header.SkipLink skipTo="#content" label={I18n.skipToContent} />
<Header.ActionBar
frontPageLabel={I18n.frontPage}
title={translations[lang].headerTitle}
titleAriaLabel={translations[lang].headerAriaLabel}
titleHref="https://hel.fi"
logo={
<Logo
src={logoSrcFromLanguageAndTheme(lang, args.theme as HeaderTheme)}
alt={translations[lang].headerTitle}
/>
}
logoAriaLabel={I18n.ariaLogo}
>
<Header.ActionBarItem id="VersionMenu" label={selectedVersion} fixedRightPosition>
{versions.map((version) => (
<Header.ActionBarSubItem label={version} selected={version === selectedVersion} href="/" />
))}
</Header.ActionBarItem>
</Header.ActionBar>
</Header>
<div id="content" />
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@
& > h4 {
padding: 0 !important;
}

&.selected {
border-left: 4px solid var(--color-black);
}
}

& .dropdownItem button {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export const HeaderActionBarItem = (properties: HeaderActionBarItemProps) => {
activeStateLabel: closeLabel,
}
: {};
const heading = visible && !fullWidth && label && avatar;

/* eslint-disable jsx-a11y/no-noninteractive-tabindex */
return (
Expand All @@ -165,7 +166,7 @@ export const HeaderActionBarItem = (properties: HeaderActionBarItemProps) => {
{hasSubItems && (
<div className={classes.dropdownWrapper}>
<div id={`${id}-dropdown`} className={dropdownClassName} ref={dropdownContentElementRef}>
{visible && !fullWidth && label && <h3>{label}</h3>}
{heading && <h3>{label}</h3>}
<ul>{children}</ul>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ h4.actionBarSubItem {
font-weight: bold;
}

&.selected {
text-decoration: underline;
}

&:focus-visible {
border: none;
outline: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export interface HeaderActionBarSubItemProps extends ElementProps {
* If bold
*/
bold?: boolean;
/**
* If selected
*/
selected?: boolean;
/**
* Hypertext Reference of the link.
*/
Expand Down Expand Up @@ -75,6 +79,7 @@ export const HeaderActionBarSubItem = forwardRef<HTMLButtonElement | HTMLAnchorE
onClick,
className,
bold,
selected,
external,
openInExternalDomainAriaLabel,
...rest
Expand All @@ -85,6 +90,7 @@ export const HeaderActionBarSubItem = forwardRef<HTMLButtonElement | HTMLAnchorE
[classes.actionBarSubItem]: true,
...(className && { [className]: true }),
[classes.bold]: bold,
[classes.selected]: selected,
});

const composeAriaLabel = () => {
Expand Down Expand Up @@ -151,7 +157,14 @@ export const HeaderActionBarSubItem = forwardRef<HTMLButtonElement | HTMLAnchorE
return isHeading ? (
<h4 className={itemClassName}>{children}</h4>
) : (
<li className={actionBarItemClasses.dropdownItem}>{children}</li>
<li
className={classNames({
[actionBarItemClasses.dropdownItem]: true,
[actionBarItemClasses.selected]: selected,
})}
>
{children}
</li>
);
},
[isHeading, itemClassName],
Expand Down
2 changes: 1 addition & 1 deletion site/gatsby-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ const Layout = require('./src/components/layout').default;

// Wraps every page in a component
exports.wrapPageElement = ({ element, props }) => {
if (props.location.pathname.includes("this-is-hds")) return <React.Fragment {...props}>{element}</React.Fragment>
if (props.location.pathname.includes('this-is-hds')) return <React.Fragment {...props}>{element}</React.Fragment>;
return <Layout {...props}>{element}</Layout>;
};
19 changes: 12 additions & 7 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 @@ -147,16 +158,10 @@ module.exports = {
resolve: `gatsby-source-filesystem`,
options: {
name: `docs`,
path: `${__dirname}/src/docs/`,
},
},
// This config is needed when pages are somewhere else than in the pages folder.
{
resolve: 'gatsby-plugin-page-creator',
options: {
path: `${__dirname}/src/docs`,
},
},
...gitSources,
{
resolve: `gatsby-plugin-mdx`,
options: {
Expand Down
100 changes: 99 additions & 1 deletion site/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,121 @@
const webpack = require('webpack');
const path = require('path');

exports.onCreateWebpackConfig = ({ actions }) => {
exports.onCreateWebpackConfig = ({ actions, getConfig }) => {
const config = getConfig();

config.plugins.push(
new webpack.NormalModuleReplacementPlugin(
/hds-core|hds-react/,
resource => {
if (resource.context.includes('.cache/gatsby-source-git/docs-release-2.17.1/site')) {
resource.request = resource.request.replace('hds-core', 'hds-2-core');
resource.request = resource.request.replace('hds-react', 'hds-2-react');
}
if (resource.context.includes('.cache/gatsby-source-git/docs-release-3.11.0/site')) {
resource.request = resource.request.replace('hds-core', 'hds-3-core');
resource.request = resource.request.replace('hds-react', 'hds-3-react');
}
}
)
);

actions.setWebpackConfig({
plugins: [
// We need to provide a polyfill for react-live library to make it work with the latest Gatsby: https://webpack.js.org/blog/2020-10-10-webpack-5-release/#automatic-nodejs-polyfills-removed
new webpack.ProvidePlugin({
process: 'process/browser',
}),
...config.plugins,
],
resolve: {
alias: {
fs$: path.resolve(__dirname, 'src/fs.js'),
'~hds-core': 'hds-2-core',
'hds-react': 'hds-react/lib',
stream: false,
},
fallback: {
crypto: require.resolve('crypto-browserify'),
},
},
/*
optimization: {
splitChunks: {
chunks: 'initial',
minChunks: 2,
minSize: 10000000,
maxSize: 0,
cacheGroups: {
default: false,
vendors: false,
},
},
},
*/
});
};

exports.createPages = async ({ actions, graphql }) => {
const { createPage } = actions;

// GraphQL query to fetch frontmatter and rendered MDX content
const result = await graphql(`
query SiteDataQuery {
allMdx {
edges {
node {
id
frontmatter {
title
slug
navTitle
customLayout
}
parent {
... on File {
relativePath
gitRemote {
ref
}
}
}
}
}
}
}
`);

if (result.errors) {
console.error(result.errors);
throw new Error('Failed to fetch MDX data');
}

// Create pages dynamically
result.data.allMdx.edges.forEach(({ node }) => {
const gitRemote = node.parent?.gitRemote?.ref;
const pathWithVersion = path.join('/', gitRemote || '', node.frontmatter.slug);

try {
const pageTemplate = require.resolve('./src/components/ContentLayoutWrapper.js');
const contentPath = './src/docs/' + node.parent.relativePath.replace('site/src/docs/', '');

console.log('createPage() ' + gitRemote + ' ' + contentPath);

const pageContent = gitRemote
? require.resolve(`./.cache/gatsby-source-git/docs-${gitRemote}/${node.parent.relativePath}`)
: require.resolve(contentPath);

createPage({
component: `${pageTemplate}?__contentFilePath=${pageContent}`,
path: pathWithVersion,
context: {
id: node.id,
frontmatter: { ...node.frontmatter, slug: pathWithVersion },
},
});
} catch (e) {
console.error(e);
}
});
};
42 changes: 25 additions & 17 deletions 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.11.0",
"version": "4.0.0",
"workspaces": {
"nohoist": [
"gatsby",
Expand All @@ -14,22 +14,24 @@
"dependencies": {
"@mdx-js/mdx": "2.3.0",
"@mdx-js/react": "2.3.0",
"gatsby": "5.11.0",
"gatsby-plugin-image": "^3.0.0",
"gatsby-plugin-manifest": "^5.12.0",
"gatsby-plugin-matomo": "^0.13.0",
"gatsby-plugin-mdx": "5.11.0",
"gatsby-plugin-no-sourcemaps": "4.24.0",
"gatsby-plugin-offline": "^6.12.0",
"gatsby-plugin-react-helmet": "^5.17.0",
"gatsby-plugin-robots-txt": "^1.7.1",
"gatsby-plugin-sass": "^5.17.0",
"gatsby-plugin-sharp": "^5.10.0",
"gatsby-remark-autolink-headers": "^5.17.0",
"gatsby-source-filesystem": "^4.17.0",
"gatsby-transformer-remark": "6.10.0",
"gatsby-transformer-sharp": "5.11.0",
"gatsby": "5.13.7",
"gatsby-plugin-image": "^3.13.1",
"gatsby-plugin-manifest": "^5.13.1",
"gatsby-plugin-matomo": "^0.16.3",
"gatsby-plugin-mdx": "5.13.1",
"gatsby-plugin-no-sourcemaps": "5.13.0",
"gatsby-plugin-offline": "^6.13.3",
"gatsby-plugin-react-helmet": "^6.13.1",
"gatsby-plugin-robots-txt": "^1.8.0",
"gatsby-plugin-sass": "^6.13.1",
"gatsby-plugin-sharp": "^5.13.1",
"gatsby-remark-autolink-headers": "^6.13.1",
"gatsby-source-filesystem": "^5.13.1",
"gatsby-source-git": "2.0.0-beta.0",
"gatsby-transformer-remark": "6.13.1",
"gatsby-transformer-sharp": "5.13.1",
"html-validate": "6.5.0",
"json5": "^2.2.3",
"prism-react-renderer": "^1.3.1",
"process-top": "^1.2.0",
"prop-types": "^15.8.1",
Expand All @@ -39,7 +41,9 @@
"react-live": "2.4.1",
"remark-gfm": "^1",
"sanitize-html": "2.10.0",
"sass": "^1.49.9"
"sass": "^1.49.9",
"body-parser": "1.20.3",
"path-to-regexp": "0.1.10"
},
"devDependencies": {
"@babel/core": "^7.0.0",
Expand All @@ -53,6 +57,10 @@
"hds-core": "3.11.0",
"hds-design-tokens": "3.11.0",
"hds-react": "3.11.0",
"hds-3-core": "npm:[email protected]",
"hds-3-react": "npm:[email protected]",
"hds-2-core": "npm:[email protected]",
"hds-2-react": "npm:[email protected]",
"inquirer": "7.1.0",
"postcss": "8",
"prettier": "2.5.1",
Expand Down
6 changes: 6 additions & 0 deletions site/src/components/ContentLayoutWrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from "react";

export default function ContentLayoutWrapper({ children }) {
return (<>{children}</>)
}

2 changes: 1 addition & 1 deletion site/src/components/LinkboxList.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
column-gap: var(--spacing-layout-xs);
display: grid;
grid-template-columns: repeat(auto-fit, minmax(216px, 1fr));
margin-top: var(--spacing-layout-m);
margin-top: var(--spacing-layout-m) !important;
row-gap: var(--spacing-layout-xs);
width: 100%;
}
Expand Down
Loading
Loading