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

docs: repo status shortcode data #1714

Merged
merged 18 commits into from
Jul 16, 2024
Merged
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
177 changes: 111 additions & 66 deletions docs/_data/repoStatus.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/_plugins/cem-shortcodes.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Renderers {
* @see https://github.com/11ty/eleventy/blob/bf7c0c0cce1b2cb01561f57fdd33db001df4cb7e/src/Plugins/RenderPlugin.js#L89-L93
* @type {DocsPage}
*/
this.docsPage = page.ctx._;
this.docsPage = page.ctx.doc;
this.manifest = this.docsPage.manifest;
Renderers.renderers.set(page, this);
}
Expand Down
27 changes: 19 additions & 8 deletions docs/_plugins/rhds.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ module.exports = function(eleventyConfig, { tagsToAlphabetize }) {
return content;
});

eleventyConfig.addFilter('getPrettyElementName', function(tagName) {
const { pfeconfig } = eleventyConfig?.globalData ?? {};
const slug = getTagNameSlug(tagName, pfeconfig);
const deslugify = eleventyConfig.getFilter('deslugify');
return pfeconfig.aliases[tagName] || deslugify(slug);
});

eleventyConfig.addFilter('getTitleFromDocs', function(docs) {
return docs.find(x => x.docsPage?.title)?.alias
?? docs[0]?.alias
Expand All @@ -204,7 +211,7 @@ module.exports = function(eleventyConfig, { tagsToAlphabetize }) {
* @see https://github.com/11ty/eleventy/blob/bf7c0c0cce1b2cb01561f57fdd33db001df4cb7e/src/Plugins/RenderPlugin.js#L89-L93
* @type {import('@patternfly/pfe-tools/11ty/DocsPage.js').DocsPage}
*/
const docsPage = this.ctx._;
const docsPage = this.ctx.doc;
return docsPage.description;
});

Expand Down Expand Up @@ -303,18 +310,22 @@ module.exports = function(eleventyConfig, { tagsToAlphabetize }) {

try {
const { glob } = await import('glob');
/** @type {(import('@patternfly/pfe-tools/11ty/DocsPage').DocsPage & { repoStatus?: any[] })[]} */
const elements = await eleventyConfig.globalData?.elements();
const { DocsPage } = await import('@patternfly/pfe-tools/11ty/DocsPage.js');
const {
Manifest,
} = await import('@patternfly/pfe-tools/custom-elements-manifest/lib/Manifest.js');

const customElementsManifestDocsPages = await eleventyConfig.globalData?.elements();
const filePaths = (await glob(`elements/*/docs/*.md`, { cwd: process.cwd() }))
.filter(x => x.match(/\d{1,3}-[\w-]+\.md$/)); // only include new style docs
const { repoStatus } = collectionApi.items.find(item => item.data?.repoStatus)?.data || [];

return filePaths
.map(filePath => {
const props = getProps(filePath);
const docsPage = elements.find(x => x.tagName === props.tagName);
if (docsPage) {
docsPage.repoStatus = repoStatus;
}
const [manifest] = Manifest.getAll();
const docsPage =
customElementsManifestDocsPages.find(x => x.tagName === props.tagName)
?? new DocsPage(manifest);
const tabs = filePaths
.filter(x => x.split('/docs/').at(0) === (`elements/${props.tagName}`))
.sort()
Expand Down
16 changes: 7 additions & 9 deletions docs/_plugins/shortcodes/renderCodeDocs.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ const html = (...args) =>
.map(x => x.replace(/^ {6}/, ''))
.join('\n');

/** @typedef {import('@patternfly/pfe-tools/11ty/DocsPage').DocsPage} DocsPage */
module.exports = function(eleventyConfig) {
eleventyConfig.addPairedShortcode('renderCodeDocs',
function renderCodeDocs(content, kwargs = {}) {
const renderers = new Renderers(this, kwargs);
return renderers.renderAll(content);
}
);
eleventyConfig
.addPairedShortcode('renderCodeDocs', function renderCodeDocs(content, kwargs = {}) {
const page = this.context?.doc ?? this.ctx;
const renderers = new Renderers(page, kwargs);
return renderers.renderAll(content);
});
};

function innerMD(content = '') {
Expand Down Expand Up @@ -49,9 +48,8 @@ class Renderers {
* NB: since the data for this shortcode is no a POJO,
* but a DocsPage instance, 11ty assigns it to this.ctx._
* @see https://github.com/11ty/eleventy/blob/bf7c0c0cce1b2cb01561f57fdd33db001df4cb7e/src/Plugins/RenderPlugin.js#L89-L93
* @type {DocsPage}
*/
this.docsPage = page.ctx._;
this.docsPage = page.doc.docsPage;
this.manifest = this.docsPage.manifest;
this.kwargs = kwargs;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/_plugins/shortcodes/renderInstallation.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function renderInstall(content, {
* @see https://github.com/11ty/eleventy/blob/bf7c0c0cce1b2cb01561f57fdd33db001df4cb7e/src/Plugins/RenderPlugin.js#L89-L93
* @type {DocsPage}
*/
const docsPage = this.ctx._;
const docsPage = this.ctx.doc;

const lightdomcssblock = /* md */`
### Lightdom CSS
Expand Down
57 changes: 25 additions & 32 deletions docs/_plugins/shortcodes/repoStatus.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,38 +70,31 @@ const STATUS_CHECKLIST = {
'Deprecated': 'Component is no longer available in the RH Elements repo',
'N/A': 'Not planned, not available, or does not apply',
},
'WebRH': {
'Ready': 'Component is available in the WebRH repo',
'In progress': 'Component will be added to the WebRH repo when finished',
'Planned': 'Component should be added to the WebRH repo at a later date',
'Deprecated': 'Component is no longer available in the WebRH repo',
'RH Shared Libs': {
'Ready': 'Component is available in the RH Shared Libs repo',
'In progress': 'Component will be added to the RH Shared Libs repo when finished',
'Planned': 'Component should be added to the RH Shared Libs repo at a later date',
'Deprecated': 'Component is no longer available in the RH Shared Libs repo',
'N/A': 'Not planned, not available, or does not apply',
},
};

/**
* Reads repo status data from global data and outputs an array with component keys
*/
function getRepoData() {
const docsPage = this.ctx._;
const allStatuses = this.ctx.repoStatus ?? docsPage?.repoStatus ?? [];
const title = this.ctx.title ?? docsPage?.title;
return allStatuses.find(
component => component.name === title && component.type === 'Element'
)?.libraries;
}

/**
* Calls getRepoData function and outputs a definition list for each component
* @param {object} [options] list heading render options
* @param {string} [options.heading] heading text
* @param {number} [options.level] heading level
*/
function repoStatusList({ heading = 'Status', level = 2 } = {}) {
function repoStatusList({ repoStatus, heading = 'Status', level = 2 } = {}) {
// Removing Documentation status from the repoStatusList
const statusList = getRepoData.call(this)?.filter(repo => repo.name !== 'Documentation');
const librariesList = this.ctx.doc ?
repoStatus.find(x => x.tagName === this.ctx.doc.tagName)
?.libraries?.filter(repo =>
repo.name !== 'Documentation')
: repoStatus.flatMap(x => x.libraries) ?? [];

if (!Array.isArray(statusList) || !statusList.length) {

if (!Array.isArray(librariesList) || !librariesList.length) {
return '';
} else {
return html`
Expand All @@ -112,7 +105,7 @@ function repoStatusList({ heading = 'Status', level = 2 } = {}) {
</h${level}>
</uxdot-copy-permalink>
<a href="#status-checklist" slot="checklist">What do these mean?</a>
<dl>${statusList.map(listItem => html`
<dl>${librariesList.map(listItem => html`
<div>
<dt>${listItem.name}:</dt>
<dd>
Expand All @@ -129,14 +122,8 @@ function repoStatusList({ heading = 'Status', level = 2 } = {}) {
/**
* Reads component status data from global data (see above) and outputs a table for Design/Code status page
*/
function repoStatusTable() {
const docsPage = this.ctx._;
const allStatuses = this.ctx.repoStatus ?? docsPage?.repoStatus ?? [];
// Filtering out 'Responsive' status from all the libraries
const elementsList = allStatuses.map(item => ({
...item,
libraries: item.libraries.filter(lib => lib.name !== 'Responsive'),
}));
function repoStatusTable({ repoStatus }) {
const elementsList = repoStatus;

if (!Array.isArray(elementsList) || !elementsList.length) {
return '';
Expand All @@ -157,7 +144,7 @@ function repoStatusTable() {
<th scope="col" data-label="Name">Name</th>
<th scope="col" data-label="Figma library">Figma library</th>
<th scope="col" data-label="RH Elements">RH Elements</th>
<th scope="col" data-label="webRH">WebRH</th>
<th scope="col" data-label="RH Shared Libs">RH Shared Libs</th>
<th scope="col" data-label="Documentation">Documentation</th>
</tr>
</thead>
Expand Down Expand Up @@ -188,8 +175,14 @@ function repoStatusTable() {
* @param {string} [options.heading] heading text
* @param {number} [options.level] heading level
*/
function repoStatusChecklist({ heading = 'Status checklist', level = 2 } = {}) {
const statusList = getRepoData.call(this)?.filter(repo => repo.name !== 'Documentation');
function repoStatusChecklist({ repoStatus, heading = 'Status checklist', level = 2 } = {}) {
// is repoStatus returning undefined ?
const statusList = this.ctx.doc ?
repoStatus.find(x => x.tagName === this.ctx.doc.tagName)
?.libraries?.filter(repo =>
repo.name !== 'Documentation')
: repoStatus.flatMap(x => x.libraries) ?? [];

if (!Array.isArray(statusList) || !statusList.length) {
return '';
} else {
Expand Down
2 changes: 1 addition & 1 deletion docs/design-code-status/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ A detailed synopsis of our web components and their implementation status.

## Web component status

{% repoStatusTable %}
{% repoStatusTable repoStatus=repoStatus %}

</section>

Expand Down
28 changes: 18 additions & 10 deletions docs/elements/elements.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
---js
{
templateEngineOverride: 'njk',
hasToc: true,
layout: 'layouts/pages/elements.njk',
permalink: '{{ doc.permalink }}',
pagination: {
data: 'collections.elementDocs',
alias: 'doc',
size: 1,
},
eleventyComputed: {
context(data) {
return data;
},
},
}
---
templateEngineOverride: njk
hasToc: true
layout: layouts/pages/elements.njk
permalink: "{{ doc.permalink }}"
pagination:
data: collections.elementDocs
alias: doc
size: 1
---
{% renderFile doc.filePath, doc.docsPage %}
{% renderFile doc.filePath, context %}
2 changes: 1 addition & 1 deletion docs/elements/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ importElements:
{%- for tagName, docs in collections.elementDocs | groupby('tagName') -%}
{%- set doc = docs[0] -%}
{%- set slug = doc.slug -%}
{%- set title = docs | getTitleFromDocs | makeSentenceCase -%}
{%- set title = tagName | getPrettyElementName | makeSentenceCase -%}
{%- set comingSoon = tagName in comingSoonItems -%}
{%- set summary = doc.docsPage.summary -%}
{% if not summary %}
Expand Down
4 changes: 2 additions & 2 deletions elements/rh-accordion/docs/00-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<img src="./accordion-sample-element.png" alt="An accordion with four collapsed panels and one expanded panel">
</uxdot-example>

{% repoStatusList %}
{% repoStatusList repoStatus=repoStatus %}

## Sample element

Expand Down Expand Up @@ -68,4 +68,4 @@
- When you need to condense a large amount of related information into sections
- When you need a way for users to read or compare sections of content simultaneously

{% repoStatusChecklist %}
{% repoStatusChecklist repoStatus=repoStatus %}
4 changes: 2 additions & 2 deletions elements/rh-alert/docs/00-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{{ tagName | getElementDescription }}

{% repoStatusList %}
{% repoStatusList repoStatus=repoStatus %}


## Sample element
Expand All @@ -20,4 +20,4 @@

[img-sample]: {{ './alert-sample.svg' | url }}

{% repoStatusChecklist %}
{% repoStatusChecklist repoStatus=repoStatus %}
4 changes: 2 additions & 2 deletions elements/rh-audio-player/docs/00-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{{ tagName | getElementDescription }}

{% repoStatusList %}
{% repoStatusList repoStatus=repoStatus %}

## Sample element

Expand Down Expand Up @@ -2637,4 +2637,4 @@
- When you want to feature audio content without directing users to other pages
- When you want to offer users with reduced hearing abilities a listening alternative using a transcript

{% repoStatusChecklist %}
{% repoStatusChecklist repoStatus=repoStatus %}
4 changes: 2 additions & 2 deletions elements/rh-avatar/docs/00-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<img src="{{ './avatar-sample.png' | url }}" alt="Image of an avatar group with a photo of a woman and text">
</uxdot-example>

{% repoStatusList %}
{% repoStatusList repoStatus=repoStatus %}


## Sample element
Expand All @@ -17,5 +17,5 @@

- When you need to represent a user who has not provided a photo or image

{% repoStatusChecklist %}
{% repoStatusChecklist repoStatus=repoStatus %}

4 changes: 2 additions & 2 deletions elements/rh-back-to-top/docs/00-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</uxdot-example>


{% repoStatusList %}
{% repoStatusList repoStatus=repoStatus %}


## Sample
Expand All @@ -19,4 +19,4 @@ View the [demos](demos/).
- When content fills up more than two screens in length at medium and large breakpoints
- When content fills up more than four screens in length at small breakpoints

{% repoStatusChecklist %}
{% repoStatusChecklist repoStatus=repoStatus %}
4 changes: 2 additions & 2 deletions elements/rh-badge/docs/00-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<img src="./badge-sample-element.png" alt="Two badges; from left to right, one badge has a light gray background with a dark gray counter number and the other badge has a blue background with a white counter number">
</uxdot-example>

{% repoStatusList %}
{% repoStatusList repoStatus=repoStatus %}


## Sample element
Expand All @@ -23,4 +23,4 @@
- When you need to reflect counts like number of objects, events, or unread items


{% repoStatusChecklist %}
{% repoStatusChecklist repoStatus=repoStatus %}
4 changes: 2 additions & 2 deletions elements/rh-blockquote/docs/00-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A blockquote is a styled quotation and citation offset from other text styles on the page.

{% repoStatusList %}
{% repoStatusList repoStatus=repoStatus %}


## Sample element
Expand Down Expand Up @@ -34,5 +34,5 @@ View a live version of this component and see how it can be customized.
- When you need to break up large portions of text


{% repoStatusChecklist %}
{% repoStatusChecklist repoStatus=repoStatus %}

4 changes: 2 additions & 2 deletions elements/rh-breadcrumb/docs/00-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<img src="{{ 'breadcrumb-sample-element.svg' | url }}" alt="Three placeholder breadcrumb links and a current page breadcrumb">
</uxdot-example>

{% repoStatusList %}
{% repoStatusList repoStatus=repoStatus %}

## Sample element

Expand All @@ -28,4 +28,4 @@
- When you want to help orient a user and and show where they are in the page hierarchy
- When you want to provide a secondary method for navigating to parent pages of the current page

{% repoStatusChecklist %}
{% repoStatusChecklist repoStatus=repoStatus %}
4 changes: 2 additions & 2 deletions elements/rh-button/docs/00-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<img src="{{ './button-sample.png' | url }}" alt="Image of Danger, Primary, Secondary, Tertiary, and Link buttons in the first row and Play and Close buttons in the second row">
</uxdot-example>

{% repoStatusList %}
{% repoStatusList repoStatus=repoStatus %}


## Sample element
Expand All @@ -19,4 +19,4 @@
- When you need to communicate actions users can take
- When you need to draw attention to the highest priority action

{% repoStatusChecklist %}
{% repoStatusChecklist repoStatus=repoStatus %}
Loading
Loading