Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions astro/markdoc.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,9 @@ export default defineMarkdocConfig({
render: component("./src/components/AgentOnly/AgentOnly.astro"),
...schema.tags["agent-only"],
},
img: {
render: component("./src/components/Img/Img.astro"),
...schema.tags.img,
},
},
});
28 changes: 28 additions & 0 deletions astro/markdoc.schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,33 @@ export default {
"agent-only": {
attributes: {},
},
img: {
selfClosing: true,
attributes: {
src: { type: String, required: true },
alt: { type: String },
caption: { type: String },
width: { type: String },
height: { type: String },
widthPercent: { type: Number },
video: { type: Boolean, default: false },
inline: { type: Boolean, default: false },
popup: { type: Boolean, default: true },
},
validate(node) {
const { widthPercent, width, height } = node.attributes;
if (widthPercent != null && (width != null || height != null)) {
return [
{
id: "img-widthPercent-conflict",
level: "error",
message:
"The `widthPercent` attribute can't be combined with `width` or `height`.",
},
];
}
return [];
},
},
},
};
60 changes: 60 additions & 0 deletions astro/src/components/Img/Img.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
import ImgController from "./ImgController";
import ImgVideo from "./ImgVideo";
import { IMAGES_URL } from "@config/images";

interface Props {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen a few flavors of these props, they can probably be rolled into one shared type?

src: string;
alt?: string;
caption?: string;
width?: string;
height?: string;
widthPercent?: number;
video?: boolean;
inline?: boolean;
popup?: boolean;
}

const {
src,
alt,
caption,
width,
height,
widthPercent,
video = false,
inline = false,
popup = true,
} = Astro.props;

const imageUrl = `${IMAGES_URL}/images/${src}`;

const srcset = `${imageUrl}?auto=format&fit=max&w=850 1x, ${imageUrl}?auto=format&fit=max&w=850&dpr=2 2x`;
const popupHref = `${imageUrl}?fit=max&auto=format`;
---

{
video ? (
<ImgVideo
client:idle
imageUrl={imageUrl}
width={width}
height={height}
widthPercent={widthPercent}
/>
) : (
<ImgController
client:idle
imageUrl={imageUrl}
srcset={srcset}
popupHref={popupHref}
alt={alt}
caption={caption}
width={width}
height={height}
widthPercent={widthPercent}
inline={inline}
popup={popup}
/>
)
}
81 changes: 81 additions & 0 deletions astro/src/components/Img/ImgController.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
.img__figure {
margin: 0 0 1rem;
}

.img__image {
max-width: 100%;
height: auto;
/* matches Hugo's $ddgray (#d6d6d6); no equivalent design token exists yet */
border: 1px solid #d6d6d6;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would still use a hugo token, declared in the same way the other hugo legacy tokens are declared, rather than hardcoding the value here. That way, we'll have it next time, and we also have an obvious hugo token to integrate or deprecate.

}

.img__link--popup {
cursor: zoom-in;
}

/* Ported from hugo/layouts/partials/global-modals/global-modals.html +
hugo/assets/scripts/components/global-modals.js (Bootstrap 5 Modal). */

.img-lightbox__overlay {
position: fixed;
inset: 0;
background: var(--hugo-modal-overlay);
z-index: 1100;
display: flex;
align-items: center;
justify-content: center;
}

.img-lightbox__overlay[hidden] {
display: none;
}

.img-lightbox__dialog {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
max-width: 90vw;
max-height: 90vh;
}

.img-lightbox__spinner,
.img-lightbox__spinner::after {
border-radius: 50%;
width: 5em;
height: 5em;
}

.img-lightbox__spinner {
font-size: 10px;
position: relative;
text-indent: -9999em;
border-top: 0.55em solid rgba(234, 234, 234, 0.5);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't keep commenting on it, but we're generally trying to avoid hard-coded colors in the CSS, even if it means we have to create a new token to avoid it (but often a reasonable alternative already exists in the tokens). This element is not required to match Hugo exactly, so don't worry about that

border-right: 0.55em solid rgba(234, 234, 234, 0.5);
border-bottom: 0.55em solid rgba(234, 234, 234, 0.5);
border-left: 0.55em solid #ffffff;
transform: translateZ(0);
animation: img-lightbox-spin 1.1s infinite linear;
}

@keyframes img-lightbox-spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

.img-lightbox__image {
max-width: 90vw;
max-height: 90vh;
object-fit: contain;
}

.img-lightbox__caption {
color: #ffffff;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably use a token to support dark mode later

text-align: center;
margin: 0.5rem 0 0;
}
Loading
Loading