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

DOP-4916: Implement SoftwareSourceCode structured data #1258

Merged
merged 16 commits into from
Sep 30, 2024

Conversation

rayangler
Copy link
Collaborator

@rayangler rayangler commented Sep 27, 2024

Stories/Links:

DOP-4916

Current Behavior:

Staging Links:

Google doesn't care about SoftwareSourceCode, so they're not present in Rich Results.

Notes:

  • Implements SoftwareSourceCode structured data for code blocks, with programmingLanguage as optional. A new mapping of different full language names has been added here to help map languages from code blocks to more SEO-friendly names. Since we don't currently have a formal list of supported languages, I'm basing this off of what I've seen and what LeafyGreen supports.
  • IO code blocks have been updated so that they're always in the HTML regardless if the output is shown on the screen or not. This allows robots to see the content, and the structured data together without needing interaction.

Ideally, these would be separate PRs, but I've added a few bonus changes based on related work. Let me know if you'd like me to create separate PRs!

  • Bonus: Removed unnecessary IDs from structured data scripts. I originally added it to VideoObject because the Docs Landing SD had it, but it seems like it's not actually used for anything. Less code to worry about!
  • Bonus: Restructured new VideoObject to adopt new StructuredData class introduced in DOP-4915: Add Tech Article Structured Data to page #1249.
  • Bonus: Fixed BreadcrumbContainer prop type. This reduces noisy console errors for local dev.

README updates

    • This PR introduces changes that should be reflected in the README, and I have made those updates.
    • This PR does not introduce changes that should be reflected in the README

background-color: ${palette.black};
color: ${palette.gray.light3};
.dark-theme & {
border-color: ${palette.gray.dark2};
Copy link
Collaborator Author

@rayangler rayangler Sep 27, 2024

Choose a reason for hiding this comment

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

No CSS changes actually applied here

@rayangler rayangler marked this pull request as ready for review September 27, 2024 14:16
Copy link
Collaborator

@seungpark seungpark left a comment

Choose a reason for hiding this comment

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

LGTM - left some minor comments below

note - CMIIW but i think there were no styling changes (just shifted from structured data HTML) !

<script id={`video-object-sd-${url}`} type="application/ld+json">
{JSON.stringify(structuredData)}
</script>
{videoObjectSd.isValid() && (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Matt had suggested doing this in the memo and returning ! 👍

Copy link
Collaborator Author

@rayangler rayangler Sep 27, 2024

Choose a reason for hiding this comment

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

Makes sense. Done. Thanks for flagging (and to Matt for suggesting)

return undefined;
}

const fullLangName = LANGUAGE_NAMES[lang];
Copy link
Collaborator

Choose a reason for hiding this comment

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

[minor] - can we check for hasOwnProperty here for cases like 'constructor' 😬

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 hope nobody is using constructor as a programming language. Done

@@ -85,77 +86,89 @@ const Code = ({
reportAnalytics('CodeblockCopied', { code });
}, [code]);

const softwareSourceCodeSd = useMemo(() => new SoftwareSourceCodeSd({ code, lang }), [code, lang]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

same minor point here for checking validity and returning !

<script
type="application/ld+json"
dangerouslySetInnerHTML={{
__html: softwareSourceCodeSd.toString(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need toString() here? Isn't it already stringified above?

Copy link
Collaborator Author

@rayangler rayangler Sep 27, 2024

Choose a reason for hiding this comment

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

Yes! Thank you for catching! Removed!

<script
type="application/ld+json"
dangerouslySetInnerHTML={{
__html: videoObjectSd.toString(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

@rayangler
Copy link
Collaborator Author

CMIIW but i think there were no styling changes (just shifted from structured data HTML) !

@seungpark You are correct! The comment above was just to flag that nothing was actually changed since the diff seemed to suggest variables and stuff were being changed

Copy link
Collaborator

@mmeigs mmeigs left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Collaborator

@seungpark seungpark left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@rayangler rayangler merged commit 07747ff into feature-structured-data Sep 30, 2024
2 checks passed
@rayangler rayangler deleted the DOP-4916-software-source-code branch September 30, 2024 18:52
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.

3 participants