Skip to content

Commit

Permalink
feat(pie-docs): DSW-2268 ingnore items for draft pages
Browse files Browse the repository at this point in the history
  • Loading branch information
maledr5 committed Aug 28, 2024
1 parent 006d48d commit d8738fa
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
12 changes: 11 additions & 1 deletion apps/pie-docs/src/_11ty/shortcodes/indexPageDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,25 @@ const path = require('path');
const defaultImageDirectory = '../../assets/img/index';
const toSlug = (string) => string.toLowerCase().replace(/\s+/g, '-');

const getDraftPagesList = (collection) => {
const draftPages = [];
collection.forEach((item) => {
if (item.data && item.data.draft) draftPages.push(item.data.title);
});
return draftPages;
};

module.exports = function ({

Check warning on line 30 in apps/pie-docs/src/_11ty/shortcodes/indexPageDisplay.js

View workflow job for this annotation

GitHub Actions / lint-js

Unexpected unnamed function
collection,
itemKey,
excludedElements,
imageSrcDirectory,
}) {
const menuItems = find(collection, itemKey);
const draftPages = getDraftPagesList(collection);

const indexElements = menuItems.map((element) => {
if (!excludedElements.includes(element.title)) {
if (!excludedElements.includes(element.title) && !draftPages.includes(element.title)) {
const menuItemSlug = toSlug(element.title);
const itemKeySlug = toSlug(itemKey);
const imageDirectory = imageSrcDirectory || defaultImageDirectory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`indexPageDisplay.js > should not render items if the page is a draft 1`] = `
"<div class=\\"c-indexPage\\">
<a class=\\"c-indexPage-link\\" href=\\"/second-sub-item/\\">
<picture>
<img src=\\"../../__tests__/_11ty/shortcodes/test-index-images/test-menu-item/second-sub-item.svg\\">
</picture>
Second Sub Item
<div class=\\"c-indexPage-background\\"></div>
</a></div>"
`;
exports[`indexPageDisplay.js > should return the expected HTML for an index page and render default image and warning when image is not provided 1`] = `
"<div class=\\"c-indexPage\\">
<a class=\\"c-indexPage-link\\" href=\\"/first-sub-item/\\">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('indexPageDisplay.js', () => {
const collectionAll = [
{
data: {
title: 'First Sub Item',
eleventyNavigation: {
key: 'First Sub Item',
parent: 'Test Menu Item',
Expand All @@ -18,6 +19,7 @@ describe('indexPageDisplay.js', () => {
},
{
data: {
title: 'Second Sub Item',
eleventyNavigation: {
key: 'Second Sub Item',
parent: 'Test Menu Item',
Expand All @@ -29,6 +31,7 @@ describe('indexPageDisplay.js', () => {
},
{
data: {
title: 'Third Sub Item without image',
eleventyNavigation: {
key: 'Third Sub Item without image',
parent: 'Test Menu Item',
Expand Down Expand Up @@ -66,4 +69,22 @@ describe('indexPageDisplay.js', () => {
expect(result)
.toMatchSnapshot();
});

it('should not render items if the page is a draft', () => {
// setup
const collectionsWithDraft = [...collectionAll];
collectionsWithDraft[0].data.draft = true;

// act
const result = indexPageDisplay({
collection: collectionsWithDraft,
itemKey: 'Test Menu Item',
excludedElements: ['Third Sub Item without image'],
imageSrcDirectory: testImageDirectory,
});

// assert
expect(result)
.toMatchSnapshot();
});
});

0 comments on commit d8738fa

Please sign in to comment.