@patternfly/documentation-framework 1.4.9 → 1.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/components/example/example.js +7 -3
- package/helpers/codesandbox.js +15 -9
- package/package.json +2 -2
- package/routes.js +3 -2
- package/scripts/md/parseMD.js +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 1.4.10 (2023-01-26)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* update codesandbox dependencies per example import ([#3367](https://github.com/patternfly/patternfly-org/issues/3367)) ([31b75a3](https://github.com/patternfly/patternfly-org/commit/31b75a346dd0ba03bb697d9917a729a32dad76be))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## 1.4.9 (2023-01-25)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @patternfly/documentation-framework
|
|
@@ -81,7 +81,11 @@ export const Example = ({
|
|
|
81
81
|
// Show dark theme switcher on full page examples
|
|
82
82
|
hasDarkThemeSwitcher = process.env.hasDarkThemeSwitcher,
|
|
83
83
|
// Map of relative imports matched to their npm package import path (passed to Codesandbox)
|
|
84
|
-
relativeImports
|
|
84
|
+
relativeImports,
|
|
85
|
+
// md file location in node_modules, used to resolve relative import paths in examples
|
|
86
|
+
relPath = '',
|
|
87
|
+
// absolute url to hosted file
|
|
88
|
+
sourceLink = ''
|
|
85
89
|
}) => {
|
|
86
90
|
if (isFullscreenPreview) {
|
|
87
91
|
isFullscreen = false;
|
|
@@ -160,13 +164,13 @@ export const Example = ({
|
|
|
160
164
|
const codeBoxParams = getParameters(
|
|
161
165
|
lang === 'html'
|
|
162
166
|
? getStaticParams(title, editorCode)
|
|
163
|
-
: getReactParams(title, editorCode, scope, lang, relativeImports)
|
|
167
|
+
: getReactParams(title, editorCode, scope, lang, relativeImports, relPath, sourceLink)
|
|
164
168
|
);
|
|
165
169
|
const fullscreenLink = loc.pathname.replace(/\/$/, '')
|
|
166
170
|
+ (loc.pathname.endsWith(source) ? '' : `/${source}`)
|
|
167
171
|
+ '/'
|
|
168
172
|
+ slugger(title);
|
|
169
|
-
|
|
173
|
+
|
|
170
174
|
return (
|
|
171
175
|
<div className="ws-example">
|
|
172
176
|
<div className="ws-example-header">
|
package/helpers/codesandbox.js
CHANGED
|
@@ -2,6 +2,7 @@ const { parse } = require('@patternfly/ast-helpers');
|
|
|
2
2
|
const versions = require('../versions.json');
|
|
3
3
|
const overpass = require('./fonts');
|
|
4
4
|
const { capitalize } = require('./capitalize');
|
|
5
|
+
const path = require('path');
|
|
5
6
|
const pathPrefix = process.env.pathPrefix;
|
|
6
7
|
|
|
7
8
|
const getStaticParams = (title, html) => {
|
|
@@ -107,7 +108,7 @@ function prettyExampleCode(title, code, declaration, identifier) {
|
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
// TODO: Make React examples work and use a template that has our assets.
|
|
110
|
-
function getReactParams(title, code, scope, lang, relativeImports) {
|
|
111
|
+
function getReactParams(title, code, scope, lang, relativeImports, relPath, sourceLink) {
|
|
111
112
|
let toRender = null;
|
|
112
113
|
try {
|
|
113
114
|
let declaration = getExampleDeclaration(code);
|
|
@@ -130,12 +131,18 @@ function getReactParams(title, code, scope, lang, relativeImports) {
|
|
|
130
131
|
catch (err) {
|
|
131
132
|
// Ignore
|
|
132
133
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
134
|
+
|
|
135
|
+
// Point to sourcelink for @patternfly images
|
|
136
|
+
if (relPath.includes('@patternfly')) {
|
|
137
|
+
const imgImportRegex = /(import \W*(\w*)\W*[^'"`]*['"`](.*\.(?:png|jpe?g|webp|gif|svg))['"])/gm;
|
|
138
|
+
let imgImportMatch;
|
|
139
|
+
while ((imgImportMatch = imgImportRegex.exec(code))) {
|
|
140
|
+
const [match, importDeclaration, imgName, relImgPath] = imgImportMatch;
|
|
141
|
+
// Point to sourceLink hosted file
|
|
142
|
+
const sourceLinkPath = new URL(relImgPath, sourceLink.replace('/blob/', '/raw/')).href;
|
|
143
|
+
const hostedImageDeclaration = `const ${imgName} = "${sourceLinkPath}"`;
|
|
144
|
+
code = code.replace(importDeclaration, hostedImageDeclaration);
|
|
145
|
+
}
|
|
139
146
|
}
|
|
140
147
|
|
|
141
148
|
const relImportRegex = /(import[\s*{])([\w*{}\n\r\t, ]+)([\s*]from\s["']([\.\/]+.*)["'])/gm;
|
|
@@ -160,8 +167,7 @@ function getReactParams(title, code, scope, lang, relativeImports) {
|
|
|
160
167
|
.filter(([pkg]) => code.includes(pkg))
|
|
161
168
|
.forEach(([pkg, version]) => dependencies[pkg] = version);
|
|
162
169
|
|
|
163
|
-
|
|
164
|
-
// Get any additional dependencies from example code
|
|
170
|
+
// Get any additional dependencies from example code, exclude relative imports
|
|
165
171
|
const importMatch = /(?:import [^'"`]*)(?:['"`])((?!.\/)[^'"`]*)/gm;
|
|
166
172
|
let depImport;
|
|
167
173
|
while (depImport = importMatch.exec(code)) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/documentation-framework",
|
|
3
3
|
"description": "A framework to build documentation for PatternFly.",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.10",
|
|
5
5
|
"author": "Red Hat",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"private": false,
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"react": "^16.8.0 || ^17.0.0",
|
|
85
85
|
"react-dom": "^16.8.0 || ^17.0.0"
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "cdc3f14e64f1d115170527afaf6b25ef971bf02f"
|
|
88
88
|
}
|
package/routes.js
CHANGED
|
@@ -28,7 +28,7 @@ const isNull = o => o === null || o === undefined;
|
|
|
28
28
|
const groupedRoutes = Object.entries(routes)
|
|
29
29
|
.filter(([_slug, { id, section }]) => !isNull(id) && !isNull(section))
|
|
30
30
|
.reduce((accum, [slug, pageData]) => {
|
|
31
|
-
const { section, subsection = null, id, title, source, katacodaLayout, hideNavItem } = pageData;
|
|
31
|
+
const { section, subsection = null, id, title, source, katacodaLayout, hideNavItem, relPath } = pageData;
|
|
32
32
|
pageData.slug = slug;
|
|
33
33
|
// add section to groupedRoutes obj if not yet created
|
|
34
34
|
accum[section] = accum[section] || {};
|
|
@@ -41,7 +41,8 @@ const groupedRoutes = Object.entries(routes)
|
|
|
41
41
|
slug: makeSlug(source, section, id, true, subsection),
|
|
42
42
|
sources: [],
|
|
43
43
|
katacodaLayout,
|
|
44
|
-
hideNavItem
|
|
44
|
+
hideNavItem,
|
|
45
|
+
relPath
|
|
45
46
|
}
|
|
46
47
|
// add page to groupedRoutes obj section or subsection
|
|
47
48
|
if (subsection) {
|
package/scripts/md/parseMD.js
CHANGED
|
@@ -86,7 +86,8 @@ function toReactComponent(mdFilePath, source, buildMode) {
|
|
|
86
86
|
sourceLink: frontmatter.sourceLink || `https://github.com/patternfly/${
|
|
87
87
|
sourceRepo}/blob/main/${
|
|
88
88
|
normalizedPath}`,
|
|
89
|
-
hideTOC: frontmatter.hideTOC || false
|
|
89
|
+
hideTOC: frontmatter.hideTOC || false,
|
|
90
|
+
relPath
|
|
90
91
|
};
|
|
91
92
|
// Temporarily override section for Demo tabs until we port this upstream
|
|
92
93
|
if (frontmatter.section === 'demos' && routes[slug.replace('demos', 'components')]) {
|