-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Optimize CDN images * updated cdn path * fix relative urls * use url instead of path * fixed path resolution * updated relative path
- Loading branch information
Showing
5 changed files
with
82 additions
and
2 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
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,23 @@ | ||
/** | ||
* Zudoku takes inspiration from some of the great features os Docusaurus. | ||
* As such we duplicate some of the Docusaurus documentation to provide | ||
* a consistent experience and make migration easier. | ||
* | ||
* Docusaurus Docs are licensed under Creative Commons Attribution 4.0 | ||
* International (CC BY 4.0). This means that any doc we copy content from | ||
* needs to be attributed and linked to the original source. | ||
*/ | ||
export function DocusaurusDocsLicense({ sourceUrl }: { sourceUrl: string }) { | ||
return ( | ||
<p> | ||
Portions of this document are adapted from from the{" "} | ||
<a href="https://docusaurus.io/">Docusaurus project</a>, created by Meta | ||
Platforms, Inc., and is licensed under the{" "} | ||
<a href="https://github.com/facebook/docusaurus/blob/main/LICENSE-docs"> | ||
Creative Commons Attribution 4.0 International | ||
</a> | ||
(CC BY 4.0) license. The <a href={sourceUrl}>original document</a> | ||
has been modified. | ||
</p> | ||
); | ||
} |
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,52 @@ | ||
import { Root } from "mdast"; | ||
import { Plugin } from "unified"; | ||
import { visit } from "unist-util-visit"; | ||
import type { VFile } from "vfile"; | ||
|
||
/** | ||
* Copies images from the /static folder to /public if they are referenced by a | ||
* @returns | ||
*/ | ||
const rehypeStaticImages: Plugin<[], Root, Root> = | ||
() => async (root, vfile: VFile) => { | ||
const promises: Promise<void>[] = []; | ||
visit(root, ["element"], (node: any, index, parent) => { | ||
promises.push( | ||
(async () => { | ||
if ( | ||
node.type === "element" && | ||
node.tagName === "img" && | ||
node.properties | ||
) { | ||
if (!node.properties.src.startsWith("http")) { | ||
let url = node.properties.src; | ||
const relativePath = url.startsWith("/public/") | ||
? `/docs${url.substring("/public".length)}` | ||
: url; | ||
if (process.env.USE_IMAGE_CDN) { | ||
node.properties.src = `https://cdn.zuplo.com${relativePath}`; | ||
} else { | ||
node.properties.src = relativePath; | ||
} | ||
} | ||
|
||
if ( | ||
node.properties.src.startsWith("https://cdn.zuplo.com/") && | ||
!node.properties.src.endsWith(".svg") && | ||
!node.properties.src.endsWith(".gif") | ||
) { | ||
const url = new URL(node.properties.src); | ||
node.properties.srcSet = [ | ||
`https://cdn.zuplo.com/cdn-cgi/image/fit=contain,width=640,format=auto${url.pathname} 640w`, | ||
`https://cdn.zuplo.com/cdn-cgi/image/fit=contain,width=960,format=auto${url.pathname} 960w`, | ||
`https://cdn.zuplo.com/cdn-cgi/image/fit=contain,width=1280,format=auto${url.pathname} 1280w`, | ||
`https://cdn.zuplo.com/cdn-cgi/image/fit=contain,width=2560,format=auto${url.pathname} 2560w`, | ||
].join(", "); | ||
} | ||
} | ||
})(), | ||
); | ||
}); | ||
await Promise.all(promises); | ||
}; | ||
export default rehypeStaticImages; |
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