@chassis-ui/docs 0.3.8 → 0.3.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +3 -2
- package/src/components/ResponsiveImage.astro +4 -1
- package/src/js/zoom.js +11 -0
- package/src/layouts/footer/Scripts.astro +1 -0
- package/src/layouts/head/Social.astro +6 -2
- package/src/layouts/header/Navigation.astro +1 -0
- package/src/libs/image.ts +27 -0
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> Shared Astro layouts, components, and utilities for Chassis documentation sites.
|
|
4
4
|
|
|
5
|
-
[](https://opensource.org/licenses/MIT) [](https://opensource.org/licenses/MIT) [](https://www.npmjs.com/package/@chassis-ui/docs) [](https://www.npmjs.com/package/@chassis-ui/docs)
|
|
6
6
|
|
|
7
7
|
## Overview
|
|
8
8
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chassis-ui/docs",
|
|
3
3
|
"description": "Shared Astro components and layouts for Chassis documentation sites.",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.10",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@astrojs/markdown-remark": "^7.0.0",
|
|
48
|
-
"@chassis-ui/css": ">=0.3.
|
|
48
|
+
"@chassis-ui/css": ">=0.3.4",
|
|
49
49
|
"@pagefind/component-ui": "^1.0.0",
|
|
50
50
|
"@shikijs/transformers": "^4.3.1",
|
|
51
51
|
"astro": "^7.0.0",
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"image-size": "^2.0.2",
|
|
60
60
|
"mdast-util-from-markdown": "^2.0.3",
|
|
61
61
|
"mdast-util-to-string": "^4.0.0",
|
|
62
|
+
"medium-zoom": "^1.1.0",
|
|
62
63
|
"remark": "^15.0.1",
|
|
63
64
|
"remark-html": "^16.0.1",
|
|
64
65
|
"unist-util-visit": "^5.1.0"
|
|
@@ -18,9 +18,11 @@ interface Props {
|
|
|
18
18
|
width?: number
|
|
19
19
|
/** Image height in pixels */
|
|
20
20
|
height?: number
|
|
21
|
+
/** Any other attribute is passed through to the rendered element. */
|
|
22
|
+
[key: string]: unknown
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
const { imgPath, alt, classes = '', lazyload = true, width, height } = Astro.props
|
|
25
|
+
const { imgPath, alt, classes = '', lazyload = true, width, height, ...rest } = Astro.props
|
|
24
26
|
|
|
25
27
|
const classNames = ['image', classes].filter(Boolean).join(' ')
|
|
26
28
|
|
|
@@ -40,4 +42,5 @@ const imgPath2x = `${basePath}/${basename}@2x${ext}`
|
|
|
40
42
|
loading={lazyload ? 'lazy' : undefined}
|
|
41
43
|
width={width}
|
|
42
44
|
height={height}
|
|
45
|
+
{...rest}
|
|
43
46
|
/>
|
package/src/js/zoom.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Enables Medium-like click-to-zoom on any image tagged data-zoomable.
|
|
3
|
+
* https://github.com/francoischalifour/medium-zoom
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import mediumZoom from 'medium-zoom'
|
|
7
|
+
|
|
8
|
+
mediumZoom('[data-zoomable]', {
|
|
9
|
+
margin: 24,
|
|
10
|
+
background: 'var(--cx-alternate-dim-main)'
|
|
11
|
+
})
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import path from 'node:path'
|
|
9
9
|
import { getConfig } from '@libs/config'
|
|
10
10
|
import { getDocsPublicFsPath } from '@libs/path'
|
|
11
|
-
import { getStaticImageSize } from '../../libs/image'
|
|
11
|
+
import { getRemoteImageSize, getStaticImageSize } from '../../libs/image'
|
|
12
12
|
import type { Layout } from '../../libs/layout'
|
|
13
13
|
|
|
14
14
|
interface Props {
|
|
@@ -25,7 +25,10 @@ interface Props {
|
|
|
25
25
|
const { description, layout, thumbnail, title } = Astro.props
|
|
26
26
|
|
|
27
27
|
const socialImageUrl = new URL(thumbnail, Astro.site)
|
|
28
|
-
const
|
|
28
|
+
const isRemoteThumbnail = /^https?:\/\//i.test(thumbnail)
|
|
29
|
+
const socialImageSize = isRemoteThumbnail
|
|
30
|
+
? await getRemoteImageSize(thumbnail)
|
|
31
|
+
: await getStaticImageSize(path.join(getDocsPublicFsPath(), thumbnail))
|
|
29
32
|
---
|
|
30
33
|
|
|
31
34
|
<meta name="twitter:card" content="summary_large_image" />
|
|
@@ -39,6 +42,7 @@ const socialImageSize = await getStaticImageSize(path.join(getDocsPublicFsPath()
|
|
|
39
42
|
<meta property="og:title" content={title} />
|
|
40
43
|
<meta property="og:description" content={description} />
|
|
41
44
|
<meta property="og:type" content={layout === 'docs' ? 'article' : 'website'} />
|
|
45
|
+
<meta property="og:site_name" content={getConfig().title} />
|
|
42
46
|
<meta property="og:image" content={socialImageUrl} />
|
|
43
47
|
<meta property="og:image:type" content="image/png" />
|
|
44
48
|
<meta property="og:image:width" content={String(socialImageSize.width)} />
|
|
@@ -99,6 +99,7 @@ const isActive = (path: string) => {
|
|
|
99
99
|
<div class="vr d-none large:d-flex my-auto large:mx-small"></div>
|
|
100
100
|
<hr class="large:d-none" />
|
|
101
101
|
</li>
|
|
102
|
+
<NavLink active={isActive('/blog')} href="/blog">Blog</NavLink>
|
|
102
103
|
<NavLink active={isActive('/examples')} href="/examples">Examples</NavLink>
|
|
103
104
|
</ul>
|
|
104
105
|
|
package/src/libs/image.ts
CHANGED
|
@@ -22,3 +22,30 @@ export async function getStaticImageSize(imagePath: string) {
|
|
|
22
22
|
|
|
23
23
|
return { height: size.height, width: size.width }
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Fetches a remote image and returns its pixel dimensions.
|
|
28
|
+
*
|
|
29
|
+
* Intended for build-time use only (e.g. generating `<meta og:image:width/height>`
|
|
30
|
+
* tags) for images hosted outside the project, such as on a CDN.
|
|
31
|
+
*
|
|
32
|
+
* @param imageUrl - Absolute URL of the image.
|
|
33
|
+
* @returns An object with `width` and `height` in pixels.
|
|
34
|
+
* @throws If the image cannot be fetched or its dimensions cannot be determined.
|
|
35
|
+
*/
|
|
36
|
+
export async function getRemoteImageSize(imageUrl: string) {
|
|
37
|
+
const response = await fetch(imageUrl)
|
|
38
|
+
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
throw new Error(`Failed to fetch remote image at '${imageUrl}' (status ${response.status}).`)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const buffer = await response.arrayBuffer()
|
|
44
|
+
const size = sizeOf(new Uint8Array(buffer))
|
|
45
|
+
|
|
46
|
+
if (!size?.height || !size?.width) {
|
|
47
|
+
throw new Error(`Failed to get size of remote image at '${imageUrl}'.`)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return { height: size.height, width: size.width }
|
|
51
|
+
}
|