-
-
Notifications
You must be signed in to change notification settings - Fork 292
seo: HowTo schema, glossary DefinedTermSet, docs landing fixes #857
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
Open
slayerjain
wants to merge
7
commits into
main
Choose a base branch
from
seo/audit-fixes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e6f719f
seo: HowTo schema, glossary DefinedTermSet, docs landing fixes
slayerjain d0dc23f
seo: address PR #857 review comments
nehagup c785858
seo: address remaining PR #857 review comments
nehagup 921aed0
seo: drop HowTo li id, fix glossary typo + guard JSON-LD URLs
nehagup 6a9e664
Merge branch 'main' into seo/audit-fixes
nehagup 9a113bc
fix(seo): drop wrong HowTo step anchor, rephrase Go SDK description
nehagup 210c5e1
fix(seo): prefix sitemap ignorePatterns with /docs/, validate HowTo s…
nehagup File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| import React from "react"; | ||
| import Head from "@docusaurus/Head"; | ||
|
|
||
| /** | ||
| * HowTo schema.org wrapper for Docusaurus MDX pages. | ||
| * | ||
| * Emits valid schema.org/HowTo JSON-LD into <head> and (optionally) renders a | ||
| * matching numbered <ol> of visible steps. Authors can pass `visible={false}` | ||
| * when the prose below already renders the steps so the JSON-LD is the only | ||
| * change to the page. | ||
| * | ||
| * Required HowTo fields per Google: name, step (array of HowToStep with name + text). | ||
| * Optional: totalTime (ISO 8601 duration), estimatedCost (MonetaryAmount), tool, supply. | ||
| * | ||
| * Example: | ||
| * <HowTo | ||
| * name="Install Keploy on Linux" | ||
| * totalTime="PT5M" | ||
| * estimatedCost={{currency: "USD", value: "0"}} | ||
| * tools={["bash", "curl"]} | ||
| * supplies={["Linux machine with kernel >= 5.10"]} | ||
| * steps={[ | ||
| * {name: "Download", text: "Run: curl ...", url: "#download"}, | ||
| * {name: "Install", text: "Run: sudo install ...", url: "#install"}, | ||
| * ]} | ||
| * visible={false} | ||
| * /> | ||
| */ | ||
| export default function HowTo({ | ||
| name, | ||
| description, | ||
| totalTime, | ||
| estimatedCost, | ||
| tools, | ||
| supplies, | ||
| image, | ||
| steps, | ||
| visible = true, | ||
| }) { | ||
| if (!name || !Array.isArray(steps) || steps.length === 0) { | ||
| // Component is a no-op without the minimum required fields. | ||
| return null; | ||
| } | ||
|
|
||
| // Filter to steps that carry both `name` and `text` per Google's HowTo | ||
| // requirements. Auto-generating "Step N" placeholders or emitting empty | ||
| // `text` produces low-quality structured data that the rich-results test | ||
| // flags. If the author gave us nothing usable, drop the schema entirely | ||
| // rather than ship a hollow HowTo. | ||
| const validSteps = steps.filter( | ||
| (s) => typeof s.name === "string" && s.name.trim() && | ||
| typeof s.text === "string" && s.text.trim(), | ||
| ); | ||
| if (validSteps.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| const schema = { | ||
| "@context": "https://schema.org", | ||
| "@type": "HowTo", | ||
| name, | ||
| step: validSteps.map((s, i) => { | ||
| const step = { | ||
| "@type": "HowToStep", | ||
| position: i + 1, | ||
| name: s.name, | ||
| text: s.text, | ||
| }; | ||
| if (s.url) step.url = s.url; | ||
| if (s.image) step.image = s.image; | ||
| return step; | ||
| }), | ||
| }; | ||
|
slayerjain marked this conversation as resolved.
|
||
|
|
||
| if (description) schema.description = description; | ||
| if (totalTime) schema.totalTime = totalTime; | ||
| if (image) schema.image = image; | ||
| if (estimatedCost && estimatedCost.value !== undefined) { | ||
| schema.estimatedCost = { | ||
| "@type": "MonetaryAmount", | ||
| currency: estimatedCost.currency || "USD", | ||
| value: String(estimatedCost.value), | ||
| }; | ||
| } | ||
| if (Array.isArray(tools) && tools.length > 0) { | ||
| schema.tool = tools.map((t) => | ||
| typeof t === "string" ? {"@type": "HowToTool", name: t} : t, | ||
| ); | ||
| } | ||
| if (Array.isArray(supplies) && supplies.length > 0) { | ||
| schema.supply = supplies.map((s) => | ||
| typeof s === "string" ? {"@type": "HowToSupply", name: s} : s, | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| <Head> | ||
| <script type="application/ld+json">{JSON.stringify(schema)}</script> | ||
| </Head> | ||
| {visible && ( | ||
| <section | ||
| aria-label={name} | ||
| style={{ | ||
| border: "1px solid var(--ifm-color-emphasis-200)", | ||
| borderRadius: "12px", | ||
| padding: "1rem 1.25rem", | ||
| margin: "1rem 0 1.5rem", | ||
| background: "var(--ifm-background-surface-color)", | ||
| }} | ||
| > | ||
| <h3 style={{marginTop: 0}}>{name}</h3> | ||
| {description && <p>{description}</p>} | ||
| <ol> | ||
| {/* Don't derive an `id` from `s.url`. In docs usage `step.url` | ||
| often points at an existing heading anchor on the page (e.g. | ||
| `#capturing-testcases`), so reusing that as a list-item id | ||
| would produce duplicate ids in the DOM whenever `visible` | ||
| is enabled. The list is the readable view; `step.url` in | ||
| the JSON-LD already covers the schema linkage. */} | ||
| {validSteps.map((s, i) => ( | ||
| <li key={i}> | ||
| <strong>{s.name}</strong> | ||
| <div>{s.text}</div> | ||
| </li> | ||
| ))} | ||
| </ol> | ||
| </section> | ||
| )} | ||
| </> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.