Skip to content

Commit 5538252

Browse files
committed
Define https://schema.org/Recipe using HTML microdata.
1 parent 84250ba commit 5538252

File tree

3 files changed

+46
-19
lines changed

3 files changed

+46
-19
lines changed

webserver/src/components/Markdown.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { md } from "@lib/markdown";
2-
import type { Component } from "solid-js";
2+
import { Component, JSX, splitProps } from "solid-js";
33

4-
export const Markdown: Component<{ source: string }> = (props) => {
5-
return <div innerHTML={md.render(props.source)} />;
4+
export const Markdown: Component<{ source: string } & JSX.HTMLAttributes<HTMLDivElement>> = (props) => {
5+
const [local, divProps] = splitProps(props, ["source"]);
6+
return <div innerHTML={md.render(local.source)} {...divProps} />;
67
};

webserver/src/components/RecipeNote.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ export const RecipeNote: Component<{
3535
}
3636
}
3737

38-
return <li id={`note-${props.note.id}`} style={{ display: "block" }}>
38+
return <li id={`note-${props.note.id}`} style={{ display: "block" }}
39+
itemprop="comment" itemscope itemtype="https://schema.org/Comment">
3940
<form method="post" action="/save_note" onSubmit={onSubmit}>
4041
<input type="hidden" name="noteId" value={props.note.id} />
4142
<div style={{ display: "flex", "flex-flow": "row wrap", "justify-content": "space-between" }}>
42-
<span><a href={`/r/${props.note.author.username}`}>{props.note.author.name}</a></span>
43+
<span itemprop="author"><a href={`/r/${props.note.author.username}`}>{props.note.author.name}</a></span>
4344
<span><time datetime={props.note.createdAt.toISOString()}>{dateFormatter.format(props.note.createdAt)}</time></span>
4445
<Switch>
4546
<Match when={props.activeUserWroteNote}>
@@ -64,9 +65,9 @@ export const RecipeNote: Component<{
6465
</label>
6566
<GrowingTextarea ref={contentTextarea} name="content" onInput={onContentInput}>{note.content}</GrowingTextarea>
6667
<p>Preview:</p>
67-
<Markdown source={note.content} />
68+
<Markdown source={note.content} itemprop="text" />
6869
</>
69-
: <Markdown source={note.content} />
70+
: <Markdown source={note.content} itemprop="text" />
7071
}
7172
</form>
7273
</li>;

webserver/src/pages/r/[username]/[slug].astro

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,49 @@ if (slug && username) {
5151
<Layout title={recipe?.name ?? "No such recipe"} user={activeUser}>
5252
{
5353
recipe ? (
54-
<main class="recipe">
55-
<h2>{recipe.name}</h2>
54+
<main class="recipe" itemscope itemtype="https://schema.org/Recipe">
55+
<h2 itemprop="name">{recipe.name}</h2>
5656
<p>
57-
by <a href={`/r/${recipe.author.username}`}>{recipe.author.name}</a>
57+
by
58+
<a href={`/r/${recipe.author.username}`} itemprop="author">
59+
{recipe.author.name}
60+
</a>
5861
{recipe.authorId === activeUser?.id ? (
5962
<a href="/account" title="Edit your name">
6063
✏️
6164
</a>
6265
) : null}
6366
</p>
64-
{recipe.servings ? <p>{recipe.servings} Servings</p> : null}
67+
{recipe.servings ? (
68+
<p itemprop="recipeYield">{recipe.servings} Servings</p>
69+
) : null}
6570
<section>
6671
<h3>Ingredients</h3>
6772
<ul>
6873
{recipe.ingredients.map((ingredient) => (
69-
<li>
70-
{ingredient.amount}
71-
{ingredient.unit}
72-
{ingredient.name +
73-
(ingredient.preparation ? `, ${ingredient.preparation}` : "")}
74+
<li
75+
itemprop="recipeIngredient"
76+
itemscope
77+
itemtype="https://schema.org/HowToSupply"
78+
>
79+
{ingredient.amount ? (
80+
<span
81+
itemprop="requiredQuantity"
82+
itemscope
83+
itemtype="https://schema.org/QuantitativeValue"
84+
>
85+
<span itemprop="value">{ingredient.amount}</span>
86+
{ingredient.unit ? (
87+
<span itemprop="unitText">{ingredient.unit}</span>
88+
) : null}
89+
</span>
90+
) : null}
91+
<span itemprop="name">
92+
{ingredient.name +
93+
(ingredient.preparation
94+
? `, ${ingredient.preparation}`
95+
: "")}
96+
</span>
7497
</li>
7598
))}
7699
</ul>
@@ -79,11 +102,13 @@ if (slug && username) {
79102
<section>
80103
<h3>Instructions</h3>
81104
{recipe.steps.length === 1 ? (
82-
<Markdown source={recipe.steps[0]!} />
105+
<div itemprop="recipeInstructions">
106+
<Markdown source={recipe.steps[0]!} />
107+
</div>
83108
) : (
84109
<ol>
85110
{recipe.steps.map((step) => (
86-
<li>
111+
<li itemprop="recipeInstructions">
87112
<Markdown source={step} />
88113
</li>
89114
))}
@@ -95,7 +120,7 @@ if (slug && username) {
95120
<h3>Categories</h3>
96121
<ul>
97122
{recipe.categories.map((category) => (
98-
<li>
123+
<li itemprop="recipeCategory">
99124
<a
100125
href={`/search?category=${encodeURIComponent(category.name)}`}
101126
>

0 commit comments

Comments
 (0)