-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add structured author data to articles.
- Loading branch information
Showing
12 changed files
with
168 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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,21 @@ | ||
load("//bzl:rules.bzl", "bazel_lint") | ||
load("//ts:rules.bzl", "ts_project") | ||
|
||
ts_project( | ||
name = "schema.org", | ||
visibility = ["//:__subpackages__"], | ||
deps = [ | ||
"//:base_defs", | ||
"//:node_modules/@types/node", | ||
"//:node_modules/@types/react", | ||
"//:node_modules/@types/react-dom", | ||
"//:node_modules/@types/trusted-types", | ||
"//:node_modules/schema-dts", | ||
"//ts/trusted_types", | ||
], | ||
) | ||
|
||
bazel_lint( | ||
name = "bazel_lint", | ||
srcs = ["BUILD.bazel"], | ||
) |
This file contains 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,24 @@ | ||
import { Thing, WithContext } from "schema-dts"; | ||
|
||
import { dangerouslyDeclareSafeHTML } from "#root/ts/trusted_types/trusted_types.js"; | ||
|
||
export interface SchemaProps<T extends Thing> { | ||
readonly children: WithContext<T> | ||
} | ||
|
||
/** | ||
* Declare a schema.org compliant schema for this page. | ||
* | ||
* This function uses {@link dangerouslyDeclareSafeHTML}; I think | ||
* it might be safe, but I can't prove it yet. So be careful! | ||
*/ | ||
export function Schema<T extends Thing>({children}: SchemaProps<T>) { | ||
return <script | ||
dangerouslySetInnerHTML={{ | ||
__html: | ||
dangerouslyDeclareSafeHTML( | ||
JSON.stringify(children)) | ||
}} | ||
type="application/ld+json" | ||
/> | ||
} |
This file contains 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,24 @@ | ||
load("//bzl:rules.bzl", "bazel_lint") | ||
load("//ts:rules.bzl", "ts_project") | ||
|
||
package(default_visibility = ["//:__subpackages__"]) | ||
|
||
ts_project( | ||
name = "trusted_types", | ||
deps = [ | ||
"//:node_modules/@types/memoizee", | ||
"//:node_modules/@types/react", | ||
"//:node_modules/@types/react-dom", | ||
"//:node_modules/@types/trusted-types", | ||
"//:node_modules/memoizee", | ||
"//:node_modules/react", | ||
"//:node_modules/trusted-types", | ||
], | ||
) | ||
|
||
bazel_lint( | ||
name = "bazel_lint", | ||
srcs = [ | ||
"BUILD.bazel", | ||
], | ||
) |
This file contains 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,41 @@ | ||
"use client"; | ||
import memoize from 'memoizee'; | ||
import { useEffect } from 'react'; | ||
import { trustedTypes } from 'trusted-types'; | ||
import { TrustedHTML } from 'trusted-types/lib'; | ||
|
||
const trustedTypesPolicy = memoize(() => | ||
trustedTypes.createPolicy("default", { | ||
createHTML: v => v | ||
}) | ||
); | ||
|
||
/** | ||
* Declare an HTML fragment as safe against XSS. If no policy | ||
* is set, then this function is an identity operation. | ||
*/ | ||
export function dangerouslyDeclareSafeHTML(html: string) { | ||
// below is needed because window can be | ||
// undefined in next prerender. | ||
const h = (trustedTypesPolicy().createHTML)(html) | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
if (globalThis?.window?.TrustedHTML && !(h instanceof TrustedHTML)) { | ||
throw new Error(`Expected TrustedHTML, got ${typeof h}`); | ||
} | ||
|
||
return h; | ||
} | ||
|
||
/** | ||
* React component that declares a trusted types policy when mounted. | ||
* | ||
* Unmounting it has no effect. | ||
*/ | ||
export function DeclareTrustedTypesPolicy() { | ||
useEffect(() => { | ||
trustedTypesPolicy(); | ||
}, []); | ||
return null; | ||
} | ||
|