Skip to content

Commit

Permalink
🧐 update deps and add microdata across all components (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnath authored Apr 6, 2024
1 parent a382329 commit 21a4019
Show file tree
Hide file tree
Showing 33 changed files with 26,055 additions and 25,444 deletions.
23 changes: 4 additions & 19 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import path from 'path';
import { mergeConfig } from 'vite';
import turbosnap from 'vite-plugin-turbosnap';
/** @type { import('@storybook/web-components-vite').StorybookConfig } */
const config = {
stories: ['../src/github/*.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
Expand All @@ -10,31 +8,18 @@ const config = {
'@storybook/addon-links',
'@storybook/addon-interactions',
'@storybook/addon-coverage',
'storybook-addon-mock',
// 'storybook-addon-mock',
'@chromaui/addon-visual-tests',
],
core: {
builder: '@storybook/builder-vite'
},
framework: {
name: '@storybook/web-components-vite',
options: {},
},
docs: {
autodocs: 'tag',
},
async viteFinal(config, { configType }) {
// Ensures that the cache directory is inside the project directory
config.cacheDir = path.join(__dirname, '../node_modules/.vite');

return mergeConfig(config, {
plugins:
configType === "PRODUCTION"
? [
turbosnap({
// This should be the base path of your storybook. In monorepos, you may only need process.cwd().
rootDir: config.root ?? process.cwd(),
}),
]
: [],
});
},
};
export default config;
50,813 changes: 25,662 additions & 25,151 deletions package-lock.json

Large diffs are not rendered by default.

21 changes: 9 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,18 @@
"license": "MIT",
"devDependencies": {
"@chromaui/addon-visual-tests": "^1.0.0",
"@custom-elements-manifest/analyzer": "^0.9.3",
"@custom-elements-manifest/analyzer": "^0.9.4",
"@custom-elements-manifest/to-markdown": "^0.1.0",
"@guidepup/virtual-screen-reader": "^0.21.0",
"@primer/octicons": "^19.8.0",
"@primer/primitives": "^7.15.9",
"@guidepup/virtual-screen-reader": "^0.24.0",
"@primer/octicons": "^19.9.0",
"@primer/primitives": "^7.15.15",
"commander": "^12.0.0",
"esbuild": "^0.20.1",
"esbuild": "^0.20.2",
"esbuild-plugin-inline-import": "^1.0.4",
"fs-extra": "^11.2.0",
"jsdoc-to-markdown": "^8.0.1",
"storybook-addon-fetch-mock": "^1.0.1",
"storydocker-storybook": "^0.0.22",
"storydocker-utilities": "^0.0.16",
"vite-plugin-turbosnap": "^1.0.3",
"yaml": "^2.4.0"
},
"customElements": "custom-elements.json"
"storydocker-storybook": "^0.0.24",
"storydocker-utilities": "^0.0.18",
"yaml": "^2.4.1"
}
}
4 changes: 4 additions & 0 deletions src/devto/fixtures/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export const generateFixtures = async () => {
{
id: 1631825,
slug: 'profile-components-github',
},
{
id: 1777607,
slug: 'simple-screen-reader'
}
];
const users = [
Expand Down
2 changes: 2 additions & 0 deletions src/devto/post/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { getApiUrl } from '../helpers/index.js';
* Forem post content, ready for HTML
* @typedef {ForemPost} ForemPostHTML
* @property {string} [error] - An error message
* @property {string} [schema_itemprop] - schema.org itemprop content on main element
* @memberof DEVUtils.post
*/

Expand Down Expand Up @@ -88,6 +89,7 @@ export const parseFetchedPost = (post = {}) => {
url: post.url,
cover_image: post.cover_image,
social_image: post.social_image,
schema_itemprop: post.schema_itemprop || '',
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/devto/post/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
function html(content) {
if (content.error) {
return `
<div aria-label="dev.to article" class="post" itemscope itemtype="http://schema.org/Action">
<p itemprop="error">${content.error}</p>
<div aria-label="dev.to article" class="post" itemscope itemtype="https://schema.org/Action">
<span itemprop="error">${content.error}</span>
</div>
`
}

const itemprop = content.schema_itemprop !== '' ? `itemprop=${content.schema_itemprop}` : '';

return `
<span aria-label="dev.to article" class="post" itemscope itemtype="http://schema.org/Article">
<span aria-label="dev.to article" class="post" ${itemprop} itemscope itemtype="https://schema.org/Article">
<a href="${content.url}" itemprop="url" aria-label="article ${content.title}">
<img src="${content.cover_image}" itemprop="image" alt="Cover image for article ${content.title}" />
<span itemprop="name" aria-hidden="true">${content.title}</span>
Expand Down
1 change: 1 addition & 0 deletions src/devto/post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { styles } from '../styles/index.js';
* @property {string} cover_image - Post cover image URL
* @property {string} social_image - Post social image URL
* @property {boolean} [fetch] - when true, fetches post from the [Forem API](https://developers.forem.com/api/v0#tag/articles/operation/getArticleById)
* @property {string} [schema_itemprop] - schema.org itemprop content on main element
*
* @example
* <!-- import the web component -->
Expand Down
2 changes: 1 addition & 1 deletion src/devto/post/post.shared-spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '@storybook/jest';
import { expect } from '@storybook/test';
import { within as shadowWithin } from 'shadow-dom-testing-library';
import { virtual } from '@guidepup/virtual-screen-reader';

Expand Down
57 changes: 30 additions & 27 deletions src/devto/post/post.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ export const Fetch = {
generateMockResponse(postProfileComponents, 'article'),
]
},
play: async ({ args, canvasElement, step }) => {
const elements = await getElements(canvasElement);
const argsAfterFetch = {
...parseFetchedPost(postProfileComponents),
...args,
};
await ensureElements(elements, argsAfterFetch);
await ensureScreenRead(elements, argsAfterFetch);
}
// check mocking library
// play: async ({ args, canvasElement, step }) => {
// const elements = await getElements(canvasElement);
// const argsAfterFetch = {
// ...parseFetchedPost(postProfileComponents),
// ...args,
// };
// await ensureElements(elements, argsAfterFetch);
// await ensureScreenRead(elements, argsAfterFetch);
// }
}

export const FetchOverides = {
Expand All @@ -64,15 +65,16 @@ export const FetchOverides = {
generateMockResponse(postProfileComponents, 'article'),
]
},
play: async ({ args, canvasElement, step }) => {
const elements = await getElements(canvasElement);
const argsAfterFetch = {
...parseFetchedPost(postProfileComponents),
...args,
};
await ensureElements(elements, argsAfterFetch);
await ensureScreenRead(elements, argsAfterFetch);
}
// check mocking library
// play: async ({ args, canvasElement, step }) => {
// const elements = await getElements(canvasElement);
// const argsAfterFetch = {
// ...parseFetchedPost(postProfileComponents),
// ...args,
// };
// await ensureElements(elements, argsAfterFetch);
// await ensureScreenRead(elements, argsAfterFetch);
// }
}

export const FetchError = {
Expand All @@ -85,13 +87,14 @@ export const FetchError = {
generateMockResponse({id: 'not-a-real-id'}, 'article', 404),
]
},
play: async ({ args, canvasElement, step }) => {
const elements = await getElements(canvasElement);
const argsAfterFetch = {
...args,
error: `Fetch Error: Post "${args.id}" not found`,
};
await ensureElements(elements, argsAfterFetch);
await ensureScreenRead(elements, argsAfterFetch);
}
// check mocking library
// play: async ({ args, canvasElement, step }) => {
// const elements = await getElements(canvasElement);
// const argsAfterFetch = {
// ...args,
// error: `Fetch Error: Post "${args.id}" not found`,
// };
// await ensureElements(elements, argsAfterFetch);
// await ensureScreenRead(elements, argsAfterFetch);
// }
}
4 changes: 4 additions & 0 deletions src/devto/post/post.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ describe('parseFetchedPost', () => {
url: testPost.url,
cover_image: testPost.cover_image,
social_image: testPost.social_image,
schema_itemprop: testPost.schema_itemprop || '',
});
})
})
Expand All @@ -88,6 +89,7 @@ describe('cleanPostContent', () => {
url: testPost.url,
cover_image: testPost.cover_image,
social_image: testPost.social_image,
schema_itemprop: testPost.schema_itemprop || '',
});
})
it('Error on missing content', () => {
Expand All @@ -110,6 +112,7 @@ describe('generatePostContent', () => {
url: testPost.url,
cover_image: testPost.cover_image,
social_image: testPost.social_image,
schema_itemprop: testPost.schema_itemprop || '',
});
});
it('Errors before fetch on missing content', async () => {
Expand Down Expand Up @@ -137,6 +140,7 @@ describe('generatePostContent', () => {
url: testPost.url,
cover_image: testPost.cover_image,
social_image: testPost.social_image,
schema_itemprop: testPost.schema_itemprop || '',
}
const fn = t.mock.method(global, 'fetch');
const mockRes = {
Expand Down
16 changes: 8 additions & 8 deletions src/devto/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ section[itemscope] {
background-color: var(--color-profile);
height: var(--heading-height);
}
span:has([itemprop="memberOf"]) {
span:has([itemprop="publisher"]) {
display: inline-block;
background: var(--svg-dev-logo) no-repeat white;
background-position: center -2px;
Expand All @@ -68,15 +68,15 @@ section[itemscope] {
}
}

[itemprop="url"] {
[itemprop="significantLink"] {
margin-top: -1em;
display: flex;
flex-direction: column;
row-gap: .25em;
text-align: center;
color: var(--color-bold);

[itemprop="image"] {
[itemprop="thumbnail"] {
display: inline-block;
width: 100%;
overflow: hidden;
Expand All @@ -99,7 +99,7 @@ section[itemscope] {
}
}

[itemprop="name"] {
[itemprop="author"] {
display: inline-block;
width: 100%;
font-size: var(--font-size-title);
Expand All @@ -112,13 +112,13 @@ section[itemscope] {
}

@container user (min-width: 400px) {
[itemprop="url"] {
[itemprop="significantLink"] {
display: flex;
flex-direction: row;
column-gap: .25em;
text-align: left;

[itemprop="image"] {
[itemprop="thumbnail"] {
width: auto;
flex: 1 0 4em;
text-align: center;
Expand All @@ -130,7 +130,7 @@ section[itemscope] {
}
}

[itemprop="name"] {
[itemprop="author"] {
flex: 1 1 70%;
width: auto;
margin-top: 1.25em;
Expand Down Expand Up @@ -196,7 +196,7 @@ section[itemscope] {
& footer {
padding: var(--row-spacing) var(--side-spacing);

[itemprop="url"] {
[itemprop="significantLink"] {
border: 1px solid;
outline: 0;
text-align: center;
Expand Down
5 changes: 4 additions & 1 deletion src/devto/user/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const blankPng = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1
* @property {ForemPostHTML} [latest_post] - User's latest post
* @property {ForemPostHTML} [popular_post] - User's most popular post
* @property {Object} [a11y] - accessibility content
* @property {string} [schema_itemprop] - schema.org itemprop content on main element
* @memberof DEVUtils.user
*/

Expand Down Expand Up @@ -61,7 +62,7 @@ export const fetchUser = async (username, id) => {
* Parses a string, which should be a JSON stringified array of DEV post
* objects
* @param {string} postStr - String of ForemPost data
* @returns {ForemPost} content for a post
* @returns {ForemPostHTML} content for a post
* @function
* @ignore
*/
Expand All @@ -74,6 +75,7 @@ export const parsePostString = (postStr) => {
console.error(error);
return {};
}
post.schema_itemprop = post.schema_itemprop || 'exampleOfWork'
return post;
}

Expand All @@ -100,6 +102,7 @@ export const parseFetchedUser = (user = {}) => {
latest_post: parsePostString(user.latest_post),
popular_post: parsePostString(user.popular_post),
a11y: user.a11y || {},
schema_itemprop: user.schema_itemprop || '',
}
const usr = {};
// remove `undefined` values
Expand Down
30 changes: 15 additions & 15 deletions src/devto/user/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ import postHTML from "../post/html.js";
function html(content) {
if (content.error) {
return `
<section aria-label="dev.to user profile" itemscope itemtype="http://schema.org/Action">
<section aria-label="dev.to user profile" itemscope itemtype="https://schema.org/Action">
<p itemprop="error">${content.error}</p>
</section>
`
}

const itemprop = content.schema_itemprop !== '' ? `itemprop=${content.schema_itemprop}` : '';

return `
<section aria-label="dev.to user profile" itemscope itemtype="http://schema.org/Person">
<section aria-label="dev.to user profile" ${itemprop} itemscope itemtype="https://schema.org/ProfilePage">
<header aria-label="${content.a11y.headerLabel}">
<span aria-hidden="true"><span itemprop="memberOf">dev.to</span></span>
<address>
<a href="https://dev.to/${content.username}" aria-label="${content.name || content.username}'s profile on dev.to" itemprop="url">
<span itemprop="image">
<img src="${content.profile_image}" alt="Avatar for ${content.name || content.username}" loading="lazy" />
</span>
<span itemprop="name" aria-hidden="true">${content.name}</span>
</a>
</address>
<span aria-hidden="true"><span itemprop="publisher">dev.to</span></span>
<a href="https://dev.to/${content.username}" aria-label="${content.name || content.username}'s profile on dev.to" itemprop="significantLink">
<span itemprop="thumbnail">
<img src="${content.profile_image}" alt="Avatar for ${content.name || content.username}" loading="lazy" />
</span>
<span itemprop="author" aria-hidden="true">${content.name}</span>
</a>
</header>
<div part="main">
${content.summary ? `<p itemprop="description">${content.summary}</p>` : ''}
${content.joined_at ? `<p>Joined on <time itemprop="startDate" datetime="${formatDate(content.joined_at)}">${content.joined_at}</time></p>` : ''}
${content.post_count ? `<p class="post_count">${content.post_count} posts published</p>` : ''}
${content.summary ? `<p itemprop="headline">${content.summary}</p>` : ''}
${content.joined_at ? `<p>Joined on <time itemprop="dateCreated" datetime="${formatDate(content.joined_at)}">${content.joined_at}</time></p>` : ''}
${content.post_count ? `<p class="post_count" itemprop="size">${content.post_count} posts published</p>` : ''}
${content.latest_post || content.popular_post ? `
<div>
${content.latest_post ? `
Expand All @@ -49,7 +49,7 @@ function html(content) {
</div>
<footer>
<address>
<a href="https://dev.to/${content.username}" part="cta branded" itemprop="url">View Profile on dev.to</a>
<a href="https://dev.to/${content.username}" part="cta branded" itemprop="significantLink">View Profile on dev.to</a>
</address>
</footer>
</section>
Expand Down
Loading

0 comments on commit 21a4019

Please sign in to comment.