mirror of
https://github.com/tiennm99/hugoDocs.git
synced 2026-10-16 08:15:10 +00:00
content: Replace calls to the code shortcode with fenced code blocks
This commit is contained in:
1 parent
b23c9a583a
commit
fd628be6ed
110 files changed
+483
-555
No files matched your search
@@ -27,7 +27,7 @@ Since the Portable Text gets converted to Markdown before it gets passed to Hugo
|
||||
|
||||
### Content Adapter
|
||||
|
||||
{{< code file=content/_content.gotmpl copy=true >}}
|
||||
```go-html-template {file="content/_content.gotmpl" copy=true}
|
||||
{{ $projectID := "mysanityprojectid" }}
|
||||
{{ $useCached := true }}
|
||||
{{ $api := "api" }}
|
||||
@@ -91,14 +91,13 @@ Since the Portable Text gets converted to Markdown before it gets passed to Hugo
|
||||
}}
|
||||
{{ $.AddPage $page }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
```
|
||||
|
||||
### Sanity setup
|
||||
|
||||
Below outlines a suitable Sanity studio setup for the above example.
|
||||
|
||||
{{< code file=sanity.config.ts copy=true >}}
|
||||
```ts {file="sanity.config.ts" copy=true}
|
||||
import {defineConfig} from 'sanity'
|
||||
import {structureTool} from 'sanity/structure'
|
||||
import {visionTool} from '@sanity/vision'
|
||||
@@ -106,7 +105,6 @@ import {schemaTypes} from './schemaTypes'
|
||||
import {media} from 'sanity-plugin-media'
|
||||
import {codeInput} from '@sanity/code-input'
|
||||
|
||||
|
||||
export default defineConfig({
|
||||
name: 'default',
|
||||
title: 'my-sanity-project',
|
||||
@@ -120,12 +118,11 @@ export default defineConfig({
|
||||
types: schemaTypes,
|
||||
},
|
||||
})
|
||||
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
Type/schema definition:
|
||||
|
||||
{{< code file=schemaTypes/postType.ts copy=true >}}
|
||||
```ts {file="schemaTypes/postType.ts" copy=true}
|
||||
import {defineField, defineType} from 'sanity'
|
||||
|
||||
export const postType = defineType({
|
||||
@@ -180,7 +177,7 @@ export const postType = defineType({
|
||||
}),
|
||||
],
|
||||
})
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
Note that the above requires some additional plugins to be installed:
|
||||
|
||||
@@ -188,11 +185,11 @@ Note that the above requires some additional plugins to be installed:
|
||||
npm i sanity-plugin-media @sanity/code-input
|
||||
```
|
||||
|
||||
{{< code file=schemaTypes/index.ts copy=true >}}
|
||||
```ts {file="schemaTypes/index.ts" copy=true}
|
||||
import {postType} from './postType'
|
||||
|
||||
export const schemaTypes = [postType]
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
## Server setup
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ Create a [passthrough render hook] to capture and render the LaTeX markup.
|
||||
|
||||
[passthrough render hook]: /render-hooks/passthrough/
|
||||
|
||||
{{< code file=layouts/_default/_markup/render-passthrough.html copy=true >}}
|
||||
```go-html-template {file="layouts/_default/_markup/render-passthrough.html" copy=true}
|
||||
{{- $opts := dict "output" "htmlAndMathml" "displayMode" (eq .Type "block") }}
|
||||
{{- with try (transform.ToMath .Inner $opts) }}
|
||||
{{- with .Err }}
|
||||
@@ -127,20 +127,20 @@ Create a [passthrough render hook] to capture and render the LaTeX markup.
|
||||
{{- $.Page.Store.Set "hasMath" true }}
|
||||
{{- end }}
|
||||
{{- end -}}
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
### Step 3
|
||||
|
||||
In your base template, conditionally include the KaTeX CSS within the head element.
|
||||
|
||||
{{< code file=layouts/_default/baseof.html copy=true >}}
|
||||
```go-html-template {file="layouts/_default/baseof.html" copy=true}
|
||||
<head>
|
||||
{{ $noop := .WordCount }}
|
||||
{{ if .Page.Store.Get "hasMath" }}
|
||||
<link href="https://cdn.jsdelivr.net/npm/katex@0.16.21/dist/katex.min.css" rel="stylesheet">
|
||||
{{ end }}
|
||||
</head>
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
In the above, note the use of a [noop](g) statement to force content rendering before we check the value of `hasMath` with the `Store.Get` method.
|
||||
|
||||
@@ -148,7 +148,7 @@ In the above, note the use of a [noop](g) statement to force content rendering b
|
||||
|
||||
Add some mathematical markup to your content, then test.
|
||||
|
||||
{{< code file=content/example.md >}}
|
||||
```text {file="content/example.md"}
|
||||
This is an inline \(a^*=x-b^*\) equation.
|
||||
|
||||
These are block equations:
|
||||
@@ -156,7 +156,7 @@ These are block equations:
|
||||
\[a^*=x-b^*\]
|
||||
|
||||
$$a^*=x-b^*$$
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
## Chemistry
|
||||
|
||||
|
||||
@@ -32,9 +32,9 @@ For example:
|
||||
|
||||
When using `transform.XMLEscape` in a template rendered by Go's [html/template] package, declare the string to be safe HTML to avoid double escaping. For example, in an RSS template:
|
||||
|
||||
{{< code file=layouts/_default/rss.xml >}}
|
||||
```xml {file="layouts/_default/rss.xml"}
|
||||
<description>{{ .Summary | transform.XMLEscape | safeHTML }}</description>
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
[disallowed characters]: https://www.w3.org/TR/xml/#charsets
|
||||
[html entities]: https://developer.mozilla.org/en-us/docs/glossary/entity
|
||||
|
||||
Reference in new issue
Block a user