feat: paragraph irudia sortzen du
This commit is contained in:
@@ -106,9 +106,18 @@ const orriBasikoak = defineCollection({
|
|||||||
deskribapena
|
deskribapena
|
||||||
edukiLibrea {
|
edukiLibrea {
|
||||||
... on ComponentParagraphTestua {
|
... on ComponentParagraphTestua {
|
||||||
|
type: __typename
|
||||||
id
|
id
|
||||||
testua
|
testua
|
||||||
}
|
}
|
||||||
|
... on ComponentParagraphIrudia {
|
||||||
|
type: __typename
|
||||||
|
id
|
||||||
|
media {
|
||||||
|
alternativeText
|
||||||
|
formats
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
|
interface Format {
|
||||||
|
url: string;
|
||||||
|
height: number;
|
||||||
|
width: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FormatsObject {
|
||||||
|
thumbnail: Format;
|
||||||
|
small?: Format;
|
||||||
|
medium?: Format;
|
||||||
|
large?: Format;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ImageMedia {
|
export interface ImageMedia {
|
||||||
alternativeText?: string;
|
alternativeText?: string;
|
||||||
formats: {
|
formats: FormatsObject;
|
||||||
thumbnail: {
|
|
||||||
url: string;
|
|
||||||
height: number;
|
|
||||||
width: number;
|
|
||||||
};
|
|
||||||
small?: {
|
|
||||||
url: string;
|
|
||||||
height: number;
|
|
||||||
width: number;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ImageData {
|
export interface ImageData {
|
||||||
@@ -21,7 +23,33 @@ export interface ImageData {
|
|||||||
width: number;
|
width: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getImageData(imageMedia: ImageMedia): ImageData {
|
export function getImageData(
|
||||||
|
imageMedia: ImageMedia,
|
||||||
|
options: { preferredFormat?: "thumbnail" | "small" | "medium" | "large" } = {
|
||||||
|
preferredFormat: "small",
|
||||||
|
}
|
||||||
|
): ImageData {
|
||||||
|
if (imageMedia.formats.large && options.preferredFormat === "large") {
|
||||||
|
return {
|
||||||
|
alt: imageMedia.alternativeText ?? "",
|
||||||
|
src: imageMedia.formats.large.url,
|
||||||
|
width: imageMedia.formats.large.width,
|
||||||
|
height: imageMedia.formats.large.height,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
imageMedia.formats.medium &&
|
||||||
|
(options.preferredFormat === "large" || options.preferredFormat == "medium")
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
alt: imageMedia.alternativeText ?? "",
|
||||||
|
src: imageMedia.formats.medium.url,
|
||||||
|
width: imageMedia.formats.medium.width,
|
||||||
|
height: imageMedia.formats.medium.height,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (imageMedia.formats.small) {
|
if (imageMedia.formats.small) {
|
||||||
return {
|
return {
|
||||||
alt: imageMedia.alternativeText ?? "",
|
alt: imageMedia.alternativeText ?? "",
|
||||||
|
|||||||
@@ -1,14 +1,24 @@
|
|||||||
import type { Markdown } from "./Markdown";
|
import type { Markdown } from "./Markdown";
|
||||||
|
import type { ImageMedia } from "models/ImageMedia";
|
||||||
|
|
||||||
|
interface ParagraphIrudia {
|
||||||
|
type: "ComponentParagraphIrudia";
|
||||||
|
id: string;
|
||||||
|
media: ImageMedia;
|
||||||
|
}
|
||||||
|
|
||||||
interface ParagraphTestua {
|
interface ParagraphTestua {
|
||||||
|
type: "ComponentParagraphTestua";
|
||||||
id: string;
|
id: string;
|
||||||
testua: Markdown;
|
testua: Markdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type Paragraph = ParagraphTestua | ParagraphIrudia;
|
||||||
|
|
||||||
export interface OrriBasikoa {
|
export interface OrriBasikoa {
|
||||||
id: string;
|
id: string;
|
||||||
izenburua: string;
|
izenburua: string;
|
||||||
slug: string;
|
slug: string;
|
||||||
deskribapena?: string;
|
deskribapena?: string;
|
||||||
edukiLibrea: ParagraphTestua[];
|
edukiLibrea: Paragraph[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import Layout from "../../layouts/Layout.astro";
|
|||||||
import Header from "views/_components/Header.astro";
|
import Header from "views/_components/Header.astro";
|
||||||
import Footer from "views/_components/Footer.astro";
|
import Footer from "views/_components/Footer.astro";
|
||||||
import MarkdownParser from "views/_components/MarkdownParser.astro";
|
import MarkdownParser from "views/_components/MarkdownParser.astro";
|
||||||
|
import { getImageData } from "models/ImageMedia";
|
||||||
|
import EdukiLibrea from "./_components/EdukiLibrea.astro";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
orriBasikoa: OrriBasikoa;
|
orriBasikoa: OrriBasikoa;
|
||||||
@@ -19,8 +21,8 @@ const { orriBasikoa } = Astro.props;
|
|||||||
<h1>{orriBasikoa.izenburua}</h1>
|
<h1>{orriBasikoa.izenburua}</h1>
|
||||||
<article>
|
<article>
|
||||||
{
|
{
|
||||||
orriBasikoa.edukiLibrea.map((paragraphTestua) => (
|
orriBasikoa.edukiLibrea.map((paragraph) => (
|
||||||
<MarkdownParser content={paragraphTestua.testua} />
|
<EdukiLibrea paragraph={paragraph} />
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
</article>
|
</article>
|
||||||
|
|||||||
23
front/src/views/orriBasikoa/_components/EdukiLibrea.astro
Normal file
23
front/src/views/orriBasikoa/_components/EdukiLibrea.astro
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
import type { Paragraph } from "models/OrriBasikoa";
|
||||||
|
import ParagraphIrudia from "./ParagraphIrudia.astro";
|
||||||
|
import ParagraphTestua from "./ParagraphTestua.astro";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
paragraph: Paragraph;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { paragraph } = Astro.props;
|
||||||
|
---
|
||||||
|
|
||||||
|
{
|
||||||
|
paragraph.type === "ComponentParagraphIrudia" && (
|
||||||
|
<ParagraphIrudia media={paragraph.media} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
paragraph.type === "ComponentParagraphTestua" && (
|
||||||
|
<ParagraphTestua testua={paragraph.testua} />
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
import { getImageData, type ImageMedia } from "models/ImageMedia";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
media: ImageMedia;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { media } = Astro.props;
|
||||||
|
|
||||||
|
const imageData = getImageData(media, { preferredFormat: "large" });
|
||||||
|
---
|
||||||
|
|
||||||
|
<img
|
||||||
|
class="irudia"
|
||||||
|
alt={media.alternativeText}
|
||||||
|
src={imageData.src}
|
||||||
|
width={imageData.width}
|
||||||
|
height={imageData.height}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
img {
|
||||||
|
width: 100%;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
import type { Markdown } from "models/Markdown";
|
||||||
|
import MarkdownParser from "views/_components/MarkdownParser.astro";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
testua: Markdown;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { testua } = Astro.props;
|
||||||
|
---
|
||||||
|
|
||||||
|
<MarkdownParser content={testua} />
|
||||||
Reference in New Issue
Block a user