Skip to content

Commit a5c9ee1

Browse files
committed
feat(tools): move 11ty plugins to pfe-tools
1 parent 2e1e89a commit a5c9ee1

File tree

13 files changed

+39
-37
lines changed

13 files changed

+39
-37
lines changed

.eleventy.cjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
44
const directoryOutputPlugin = require('@11ty/eleventy-plugin-directory-output');
55

66
const pfeAssetsPlugin = require('./docs/_plugins/pfe-assets.cjs');
7-
const customElementsManifestPlugin = require('./docs/_plugins/custom-elements-manifest.cjs');
8-
const orderTagsPlugin = require('./docs/_plugins/order-tags.cjs');
9-
const todosPlugin = require('./docs/_plugins/todos.cjs');
7+
8+
const customElementsManifestPlugin = require('@patternfly/pfe-tools/11ty/plugins/custom-elements-manifest.cjs');
9+
const orderTagsPlugin = require('@patternfly/pfe-tools/11ty/plugins/order-tags.cjs');
10+
const todosPlugin = require('@patternfly/pfe-tools/11ty/plugins/todos.cjs');
1011

1112
const markdownIt = require('markdown-it');
1213
const markdownItAnchor = require('markdown-it-anchor');

docs/_data/core.cjs

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/_data/corePackages.cjs

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/_data/elements.cjs

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/_data/elementsPackages.cjs

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/_data/meta.cjs

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/_includes/layout-demo.njk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1">
66
<meta name="description" content="PatternFly Elements: A set of community-created web components based on PatternFly design.">
7+
<meta name="pfe-auto-reveal" content="true">
78
<link href="/brand/logo/svg/pfe-icon-blue.svg" rel="shortcut icon">
89
<title>{{ element.title }} | PatternFly Elements</title>
910
<link rel="preconnect" href="https://ga.jspm.io">

docs/_plugins/pfe-assets.cjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ function demoPaths(content) {
6161

6262
module.exports = {
6363
configFunction(eleventyConfig) {
64-
eleventyConfig.addWatchTarget('tools/pfe-tools/11ty/**/*.{js,njk}');
6564
eleventyConfig.addPassthroughCopy('docs/bundle.{js,map,ts}');
6665
eleventyConfig.addPassthroughCopy('docs/pfe.min.{map,css}');
6766
eleventyConfig.addPassthroughCopy('docs/demo.{js,map,ts}');

docs/components/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ permalink: /components/index.html
2424
{%- if element.docsPath -%}
2525
<div class="component-preview">
2626
<div class="component-preview--container">
27-
{%- if meta.env == "prod" -%}
27+
{%- if env.ELEVENTY_ENV == "prod" -%}
2828
<a href="/components/{{ element.slug }}/" aria-label="{{ element.title }}">
2929
<div class="preview-image" style="background-image: url(/components/{{ element.slug }}/docs/preview.png);"></div>
3030
</a>
@@ -39,7 +39,7 @@ permalink: /components/index.html
3939
<a href="/components/{{ element.slug }}/">{{ element.title }}</a>
4040
</h3>
4141
{% renderTemplate "njk,md", element=element %}{{ element.summary }}{% endrenderTemplate %}
42-
{%- if meta.env != "prod" -%}
42+
{%- if env.ELEVENTY_ENV != "prod" -%}
4343
<pfe-cta><a href="/components/{{ element.slug }}/">Component overview</a></pfe-cta>
4444
{%- endif -%}
4545
</div>

docs/_plugins/custom-elements-manifest.cjs renamed to tools/pfe-tools/11ty/plugins/custom-elements-manifest.cjs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const elementsPackages = require('../_data/elementsPackages.cjs');
2-
31
const { EleventyRenderPlugin } = require('@11ty/eleventy');
42

53
let elements;
@@ -9,25 +7,50 @@ function getTagName(url) {
97
return `pfe-${tagName}`;
108
}
119

10+
async function elementsPackages() {
11+
const { getPackageData } = await import('@patternfly/pfe-tools/11ty');
12+
return getPackageData('elements', 'components');
13+
}
14+
15+
async function corePackages() {
16+
const { getPackageData } = await import('@patternfly/pfe-tools/11ty');
17+
return getPackageData('core');
18+
}
19+
1220
// it's an 11ty api
1321
/* eslint-disable no-invalid-this */
1422

1523
async function getDocsPage(tagName) {
1624
// NB: I think this is new with 11ty 1.0.0. Maybe it's the pagination value? Not sure how bad of an abuse this is
1725
if (this.ctx._?.constructor?.name === 'DocsPage') {
1826
return this.ctx._;
27+
} else {
28+
elements ??= await elementsPackages();
29+
tagName ??= getTagName(this.page.url);
30+
return elements.get(tagName);
1931
}
20-
elements ??= await elementsPackages();
21-
tagName ??= getTagName(this.page.url);
22-
return elements.get(tagName);
2332
}
2433

2534
// TODO: programmable package scopes, etc
2635
module.exports = function configFunction(eleventyConfig) {
2736
// add `renderTemplate` filter
2837
eleventyConfig.addPlugin(EleventyRenderPlugin);
2938

30-
eleventyConfig.addWatchTarget('tools/pfe-tools/11ty/*.js');
39+
eleventyConfig.addGlobalData('env', () => process.env);
40+
41+
eleventyConfig.addGlobalData('elementsPackages', elementsPackages);
42+
eleventyConfig.addGlobalData('corePackages', corePackages);
43+
eleventyConfig.addGlobalData('core', async function core() {
44+
return [...new Set((await corePackages()).values())]
45+
.sort((a, b) => a.package.name > b.package.name ? 1 : -1);
46+
});
47+
eleventyConfig.addGlobalData('elements', async function elements() {
48+
return [...new Set((await elementsPackages()).values())]
49+
.sort((a, b) => a.tagName > b.tagName ? 1 : -1);
50+
});
51+
52+
const toolsFiles = require.resolve('@patternfly/pfe-tools/11ty').replace('index.js', '**/*.{js,njk}');
53+
eleventyConfig.addWatchTarget(toolsFiles);
3154

3255
// copied from DocsPage
3356
eleventyConfig.addPairedAsyncShortcode('band', async function(content, kwargs) {

0 commit comments

Comments
 (0)