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

feat: implement a shared Glitch shortcode #68

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mamieorine
Copy link
Collaborator

Resolves #64

The Glitch shortcode on both d.d.c and web.dev have the same design and code structure. So, this shortcode can be moved into webdev-infra so it will be a shared shortcode which can be used by both d.c.c and web.dev.

Changes in this pull request:

  • Adds a new shared Glitch shortcode

Usages:

{% Glitch {
  id: 'tabindex-zero',
  path: 'index.html',
  previewSize: 0,
  allow: []
} %}

{% Glitch 'tabindex-zero' %}

Copy link
Collaborator

@matthiasrohmer matthiasrohmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Maya! Left some comments. Did you already cross-test this with web.dev and d.c.c to see if there are any regressions?

*/

const {html} = require('common-tags');
const {escape, stringify} = require('querystring');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the Node.js native URL module instead.

if (!id) {
return;
}
const url = 'https://glitch.com/embed/#!/embed/' + escape(id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use new URL instead.

Comment on lines 41 to 49
const defaultAllow = [
'camera',
'clipboard-read',
'clipboard-write',
'encrypted-media',
'geolocation',
'microphone',
'midi',
];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to top of file as configuration constant, like const DEFAULT_ALLOW.

).join('; ');
}

const src = `${url}?${stringify(queryParams)}`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use URLSearchParams instead.

Comment on lines 85 to 93
if (path) {
queryParams.path = path;
}
if (highlights) {
queryParams.highlights = highlights;
}
if (typeof previewSize === 'number') {
queryParams.previewSize = previewSize;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have another look at the d.c.c Glitch implementation. It already uses URLSearchParams: https://github.com/GoogleChrome/developer.chrome.com/blob/main/site/_shortcodes/Glitch.js

Copy link
Collaborator

@matthiasrohmer matthiasrohmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for @mamieorine to test with web.dev and d.c.c and report back.

@mamieorine
Copy link
Collaborator Author

@matthiasrohmer I have tested a shared Glitch shortcode with web.dev and d.c.c, it works fine with both site.

The results of testing a shortcode with both web.dev and d.c.c. are shown below:

Copy link
Collaborator

@matthiasrohmer matthiasrohmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review, looks fine just one note.

Comment on lines 86 to 91
let allow = Array.from(new Set([...DEFAULT_ALLOW])).join('; ');
if (glitchProps.allow) {
allow = Array.from(
new Set([...DEFAULT_ALLOW, ...expandAllowSource(glitchProps.allow)])
).join('; ');
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just seeing this now, something weird is happening here: DEFAULT_ALLOW is always the same, and it's an array. So:

DEFAULT_ALLOW;
[...DEFAULT_ALLOW];
Array.from(new Set([...DEFAULT_ALLOW]))

are all the same. The spread into a new array only makes sense in L89.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed it. I have no idea why I wrote that weird code 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move Glitch shortcode from both d.d.c and webdev into webdev-infra
2 participants