Skip to content

Commit 987b72a

Browse files
committed
add component to use images from /static
1 parent 9736c19 commit 987b72a

3 files changed

Lines changed: 31 additions & 5 deletions

File tree

src/components/StaticImage.astro

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
import type { ImageMetadata } from 'astro';
3+
import { Image } from 'astro:assets';
4+
5+
interface Props {
6+
path?: string | string[];
7+
alt: string;
8+
}
9+
10+
const { path, alt, ...rest } = Astro.props;
11+
const actualPaths = Array.isArray(path) ? path.map(p => `../../static${p}`) : [`../../static${path}`];
12+
13+
const images = import.meta.glob<{ default: ImageMetadata }>('../../static/**/*.{jpeg,jpg,png,gif,svg}');
14+
15+
for (const path of actualPaths) {
16+
if (!images[path]) throw new Error(`"${path}" does not exist in glob: "static/*.{jpeg,jpg,png,gif,svg}"`);
17+
}
18+
---
19+
{actualPaths.length === 1 ?
20+
<Image src={images[actualPaths[0]]()} alt={alt} {...rest} /> :
21+
(
22+
<Image src={images[actualPaths[0]]()} alt={alt} {...rest} data-theme-only="light" />
23+
<Image src={images[actualPaths[1]]()} alt={alt} {...rest} data-theme-only="dark" />
24+
)
25+
}

src/content/docs/docs/reference/layers.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ sidebar:
55
---
66

77
import { Aside } from '@astrojs/starlight/components';
8+
import StaticImage from '../../../../components/StaticImage.astro';
89

910
Layers are the first level of organisational hierarchy in Feature-Sliced Design. Their purpose is to separate code based on how much responsibility it needs and how many other modules in the app it depends on. Every layer carries special semantic meaning to help you determine how much responsibility you should allocate to your code.
1011

1112
There are **7 layers** in total, arranged from most responsibility and&nbsp;dependency to least:
1213

13-
<img src="../../../../../static/img/layers/folders-graphic-light.svg" data-theme-only="light" width="180" style={{ float: "right", margin: "0 1em" }} alt="A file system tree, with a single root folder called src and then seven subfolders: app, processes, pages, widgets, features, entities, shared. The processes folder is slightly faded out." />
14-
<img src="../../../../../static/img/layers/folders-graphic-dark.svg" data-theme-only="dark" width="180" style={{ float: "right", margin: "0 1em" }} alt="A file system tree, with a single root folder called src and then seven subfolders: app, processes, pages, widgets, features, entities, shared. The processes folder is slightly faded out." />
14+
<StaticImage path={['/img/layers/folders-graphic-light.svg', '/img/layers/folders-graphic-dark.svg']} width="180" style={{ float: "right", margin: "0 1em" }} alt="A file system tree, with a single root folder called src and then seven subfolders: app, processes, pages, widgets, features, entities, shared. The processes folder is slightly faded out." />
1515

1616
1. App
1717
2. Processes (deprecated)

src/content/docs/docs/reference/slices-segments.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ sidebar:
44
order: 2
55
---
66

7+
import StaticImage from '../../../../components/StaticImage.astro';
8+
79
## Slices
810

911
Slices are the second level in the organizational hierarchy of Feature-Sliced Design. Their main purpose is to group code by its meaning for the product, business, or just the application.
@@ -17,8 +19,7 @@ The layers Shared and App don't contain slices. That is because Shared should co
1719
Slices are meant to be independent and highly cohesive groups of code files. The graphic below might help to visualize the tricky concepts of _cohesion_ and _coupling_:
1820

1921
<figure>
20-
<img src="../../../../../static/img/coupling-cohesion-light.svg" data-theme-only="light" alt="" />
21-
<img src="../../../../../static/img/coupling-cohesion-dark.svg" data-theme-only="dark" alt="" />
22+
<StaticImage path={['/img/coupling-cohesion-light.svg', '/img/coupling-cohesion-dark.svg']} alt="Coupling and cohesion" />
2223
<figcaption>
2324
Image inspired by https://enterprisecraftsmanship.com/posts/cohesion-coupling-difference/
2425
</figcaption>
@@ -44,7 +45,7 @@ Read more about the rationale of public APIs and the best practices on creating
4445

4546
Closely related slices can be structurally grouped in a folder, but they should exercise the same isolation rules as other slices — there should be **no code sharing** in that folder.
4647

47-
![Features "compose", "like" and "delete" grouped in a folder "post". In that folder there is also a file "some-shared-code.ts" that is crossed out to imply that it's not allowed.](../../../../../static/img/graphic-nested-slices.svg)
48+
<StaticImage path="/img/graphic-nested-slices.svg" alt="Features 'compose', 'like' and 'delete' grouped in a folder 'post'. In that folder there is also a file 'some-shared-code.ts' that is crossed out to imply that it's not allowed." />
4849

4950
## Segments
5051

0 commit comments

Comments
 (0)