-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Added LD+JSON asset and test case #1936
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! π―
src/Parser.js
Outdated
@@ -20,6 +20,7 @@ class Parser { | |||
this.registerExtension('vue', './assets/VueAsset'); | |||
this.registerExtension('json', './assets/JSONAsset'); | |||
this.registerExtension('json5', './assets/JSONAsset'); | |||
this.registerExtension('json-ld', './assets/JSONLDAsset'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's make the extension .jsonld
as specified here: https://json-ld.org/spec/latest/json-ld/#iana-considerations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π
src/assets/JSONLDAsset.js
Outdated
"logo", | ||
"photo", | ||
"image" | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start. I guess we should go through the specs and find all the possible attributes that are URLs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if they list every single property, but https://schema.org/ImageObject has a dependents list: "Instances of ImageObject may appear as values for the following properties"
@devongovett , can I add a new cli parameter ? I can't really see another way to (properly) solve the issue with URLs/paths. Or reuse |
src/assets/HTMLAsset.js
Outdated
@@ -247,13 +249,15 @@ class HTMLAsset extends Asset { | |||
} else if (type === 'tag') { | |||
if ( | |||
(rendition.type === 'js' && node.tag === 'script') || | |||
(rendition.type === 'css' && node.tag === 'style') | |||
(rendition.type === 'css' && node.tag === 'style') || | |||
(rendition.type === 'jsonld' && node.tag === 'script') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just check isAstDirty
?
src/assets/JSONLDAsset.js
Outdated
collectDependencies() { | ||
for (let schemaKey in this.ast) { | ||
// only check for single values, not nested data | ||
// todo: check for nested data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make a recursive function for this?
src/assets/JSONLDAsset.js
Outdated
this.ast[schemaKey] = assetPath; | ||
this.isAstDirty = true; | ||
|
||
if (this.options.publicURL === '/') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so I take it JSON LD requires full URLs not paths? If so, then this is probably fine to show a warning.
Maybe this check should check whether the public URL starts with / instead of fully equaling it?
src/assets/JSONLDAsset.js
Outdated
this.isAstDirty = true; | ||
|
||
if (this.options.publicURL === '/') { | ||
console.warn( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the parcel logger for this
src/assets/JSONLDAsset.js
Outdated
'image', | ||
'thumbnail', | ||
'screenshot', | ||
'primaryImageOfPage' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could look through https://schema.org/URL for more URL instances. Maybe Video/MediaObject and a few others of those would be good to support too.
I still think |
src/assets/HTMLAsset.js
Outdated
) { | ||
node.content = rendition.value; | ||
} | ||
|
||
// Delete "type" attribute, since CSS and JS are the defaults. | ||
if (node.attrs) { | ||
// Unless it's application/ld+json | ||
if (node.attrs && node.attrs.type !== 'application/ld+json') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick fix. Proper solution: #1924
@devongovett needs a final review |
Closes #1935
π TODO
Review β¨
π DONE
public-url
parameter. Avoids creating a new flag but spams the DOMmsapplication-config
. Complements Add support for HTML meta assetsΒ #747type="application/ld+json"
Minify JSON (Handled by htmlnanotransform
)JSON.stringify()
π Possible Solution for URLs
Ask for URL using a new parameter (
published-url
?)Assume the user will enter a full URL (warn otherwise) in the schema
Use
public-url