Skip to content

Commit f62bffb

Browse files
committed
use replace <img> with StaticImage
1 parent 9595414 commit f62bffb

File tree

17 files changed

+214
-134
lines changed

17 files changed

+214
-134
lines changed

src/components/StaticImage.astro

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,46 @@
11
---
2-
import type { ImageMetadata } from 'astro';
3-
import { Image } from 'astro:assets';
2+
import type { ImageMetadata } from "astro";
3+
import { Image } from "astro:assets";
44
55
interface Props {
6-
path?: string | string[];
7-
alt: string;
6+
path?: string | string[];
7+
alt: string;
88
}
99
1010
const { path, alt, ...rest } = Astro.props;
11-
const actualPaths = Array.isArray(path) ? path.map(p => `../../static${p}`) : [`../../static${path}`];
11+
const actualPaths = Array.isArray(path)
12+
? path.map((p) => `../../static${p}`)
13+
: [`../../static${path}`];
1214
13-
const images = import.meta.glob<{ default: ImageMetadata }>('../../static/**/*.{jpeg,jpg,png,gif,svg}');
15+
const images = import.meta.glob<{ default: ImageMetadata }>(
16+
"../../static/**/*.{jpeg,jpg,png,gif,svg}",
17+
);
1418
1519
for (const path of actualPaths) {
16-
if (!images[path]) throw new Error(`"${path}" does not exist in glob: "static/*.{jpeg,jpg,png,gif,svg}"`);
20+
if (!images[path])
21+
throw new Error(
22+
`"${path}" does not exist in glob: "static/*.{jpeg,jpg,png,gif,svg}"`,
23+
);
1724
}
1825
---
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-
)
26+
27+
{
28+
actualPaths.length === 1 ? (
29+
<Image src={images[actualPaths[0]]()} alt={alt} {...rest} />
30+
) : (
31+
<>
32+
<Image
33+
src={images[actualPaths[0]]()}
34+
alt={alt}
35+
{...rest}
36+
data-theme-only="light"
37+
/>
38+
<Image
39+
src={images[actualPaths[1]]()}
40+
alt={alt}
41+
{...rest}
42+
data-theme-only="dark"
43+
/>
44+
</>
45+
)
2546
}

src/content/docs/docs/about/promote/integration.mdx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ sidebar:
88

99
First 5 minutes (RU):
1010

11-
<iframe className="youtube" src="https://www.youtube.com/embed/TFA6zRO_Cl0?start=2110" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
11+
<iframe
12+
className="youtube"
13+
src="https://www.youtube.com/embed/TFA6zRO_Cl0?start=2110"
14+
title="YouTube video player"
15+
frameborder="0"
16+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
17+
allowfullscreen
18+
style="width: 100%; height: 700px;"
19+
></iframe>
1220

1321
## Also
1422

src/content/docs/docs/get-started/overview.mdx

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

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

910
**Feature-Sliced Design** (FSD) is an architectural methodology for scaffolding front-end applications. Simply put, it's a compilation of rules and conventions on organizing code. The main purpose of this methodology is to make the project more understandable and stable in the face of ever-changing business requirements.
1011

@@ -52,7 +53,7 @@ These top-level folders are called _layers_. Let's look deeper:
5253

5354
</FileTree>
5455

55-
Folders inside `📂 pages` are called _slices_. They divide the layer by domain (in this case, by pages).
56+
Folders inside `📂 pages` are called _slices_. They divide the layer by domain (in this case, by pages).
5657

5758
Folders inside `📂 app`, `📂 shared`, and `📂 pages/article-reader` are called _segments_, and they divide slices (or layers) by technical purpose, i.e. what the code is for.
5859

@@ -61,7 +62,10 @@ Folders inside `📂 app`, `📂 shared`, and `📂 pages/article-reader` are ca
6162
Layers, slices, and segments form a hierarchy like this:
6263

6364
<figure>
64-
![Hierarchy of FSD concepts, described below](../../../../../static/img/visual_schema.jpg)
65+
<StaticImage
66+
path="/img/visual_schema.jpg"
67+
alt="Hierarchy of FSD concepts, described below"
68+
/>
6569

6670
<figcaption style={{ fontStyle: "italic", fontSize: "0.9em" }}>
6771
<p>Pictured above: three pillars, labeled left to right as "Layers", "Slices", and "Segments" respectively.</p>
@@ -112,18 +116,18 @@ Usually these segments are enough for most layers, you would only create your ow
112116

113117
## Advantages \{#advantages\}
114118

115-
- **Uniformity**
119+
- **Uniformity**
116120
Since the structure is standardized, projects become more uniform, which makes onboarding new members easier for the team.
117121

118-
- **Stability in face of changes and refactoring**
119-
A module on one layer cannot use other modules on the same layer, or the layers above.
122+
- **Stability in face of changes and refactoring**
123+
A module on one layer cannot use other modules on the same layer, or the layers above.
120124
This allows you to make isolated modifications without unforeseen consequences to the rest of the app.
121125

122-
- **Controlled reuse of logic**
123-
Depending on the layer, you can make code very reusable or very local.
124-
This keeps a balance between following the **DRY** principle and practicality.
126+
- **Controlled reuse of logic**
127+
Depending on the layer, you can make code very reusable or very local.
128+
This keeps a balance between following the **DRY** principle and practicality.
125129

126-
- **Orientation to business and users needs**
130+
- **Orientation to business and users needs**
127131
The app is split into business domains and usage of the business language is encouraged in naming, so that you can do useful product work without fully understanding all other unrelated parts of the project.
128132

129133
## Incremental adoption \{#incremental-adoption\}

src/content/docs/docs/get-started/tutorial.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Whatever is inside folders like `pages/feed` or `shared/ui` is only known to tho
136136

137137
### Large reused blocks in the UI
138138

139-
Earlier we made a note to revisit the header that appears on every page. Rebuilding it from scratch on every page would be impractical, so it’s only natural to want to reuse it. We already have Shared to facilitate code reuse, however, there’s a caveat to putting large blocks of UI in Shared — the Shared layer is not supposed to know about any of the layers above.
139+
Earlier we made a note to revisit the header that appears on every page. Rebuilding it from scratch on every page would be impractical, so it’s only natural to want to reuse it. We already have Shared to facilitate code reuse, however, there’s a caveat to putting large blocks of UI in Shared — the Shared layer is not supposed to know about any of the layers above.
140140

141141
Between Shared and Pages there are three other layers: Entities, Features, and Widgets. Some projects may have something in those layers that they need in a large reusable block, and that means we can’t put that reusable block in Shared, or else it would be importing from upper layers, which is prohibited. That’s where the Widgets layer comes in. It is located above Shared, Entities, and Features, so it can use them all.
142142

@@ -150,9 +150,9 @@ Let’s also examine a page that’s intended for editing, not reading. For exam
150150

151151
It looks trivial, but contains several aspects of application development that we haven’t explored yet — form validation, error states, and data persistence.
152152

153-
If we were to build this page, we would grab some inputs and buttons from Shared and put together a form in the `ui` segment of this page. Then, in the `api` segment, we would define a mutation request to create the article on the backend.
153+
If we were to build this page, we would grab some inputs and buttons from Shared and put together a form in the `ui` segment of this page. Then, in the `api` segment, we would define a mutation request to create the article on the backend.
154154

155-
To validate the request before sending, we need a validation schema, and a good place for it is the `model` segment, since it’s the data model. There we will produce error messages and display them using another component in the `ui` segment.
155+
To validate the request before sending, we need a validation schema, and a good place for it is the `model` segment, since it’s the data model. There we will produce error messages and display them using another component in the `ui` segment.
156156

157157
To improve user experience, we could also persist the inputs to prevent accidental data loss. This is also a job of the `model` segment.
158158

@@ -524,7 +524,7 @@ export function FeedPage() {
524524
</div>
525525
</div>
526526
);
527-
}
527+
}
528528
```
529529

530530
Then we need to use the `tag` search parameter in our loader. Change the `loader` function in `pages/feed/api/loader.ts` to the following:

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ Layers are the first level of organisational hierarchy in Feature-Sliced Design.
1111

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

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." />
14+
<StaticImage
15+
path={['/img/layers/folders-graphic-light.svg', '/img/layers/folders-graphic-dark.svg']}
16+
width="180"
17+
style={{ float: "right", margin: "0 1em" }}
18+
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."
19+
/>
1520

1621
1. App
1722
2. Processes (deprecated)
@@ -50,9 +55,9 @@ This layer, like the App layer, _does not contain slices_. Slices are intended t
5055
Here are the segments that you can typically find in this layer:
5156

5257
- `📁 api` — the API client and potentially also functions to make requests to specific backend endpoints.
53-
- `📁 ui` — the application's UI kit.
58+
- `📁 ui` — the application's UI kit.
5459
Components on this layer should not contain business logic, but it's okay for them to be business-themed. For example, you can put the company logo and page layout here. Components with UI logic are also allowed (for example, autocomplete or a search bar).
55-
- `📁 lib` — a collection of internal libraries.
60+
- `📁 lib` — a collection of internal libraries.
5661
This folder should not be treated as helpers or utilities ([read here why these folders often turn into a dump][ext-sova-utility-dump]). Instead, every library in this folder should have one area of focus, for example, dates, colors, text manipulation, etc. That area of focus should be documented in a README file. The developers in your team should know what can and cannot be added to these libraries.
5762
- `📁 config` — environment variables, global feature flags and other global configuration for your app.
5863
- `📁 routes` — route constants or patterns for matching routes.

src/content/docs/docs/reference/public-api.mdx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ sidebar:
55
---
66

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

910
A public API is a _contract_ between a group of modules, like a slice, and the code that uses it. It also acts as a gate, only allowing access to certain objects, and only through that public API.
1011

@@ -70,8 +71,11 @@ Index files like `index.js`, also known as barrel files, are the most common way
7071
Circular import is when two or more files import each other in a circle.
7172

7273
<figure>
73-
<img src="../../../../../static/img/circular-import-light.svg" data-theme-only="light" width="60%" alt="Three files importing each other in a circle" />
74-
<img src="../../../../../static/img/circular-import-dark.svg" data-theme-only="dark" width="60%" alt="Three files importing each other in a circle" />
74+
<StaticImage
75+
path={['/img/circular-import-light.svg', '/img/circular-import-dark.svg']}
76+
style={{ width: "60%", marginLeft: "auto", marginRight: "auto" }}
77+
alt="Three files importing each other in a circle"
78+
/>
7579
<figcaption>
7680
Pictured above: three files, `fileA.js`, `fileB.js`, and `fileC.js`, importing each other in a circle.
7781
</figcaption>
@@ -147,9 +151,9 @@ Having a large amount of index files in a project can slow down the development
147151

148152
There are several things you can do to tackle this issue:
149153
1. The same advice as in ["Large bundles and broken tree-shaking in Shared" issue](#large-bundles) — have separate index files for each component/library in `shared/ui` and `shared/lib` instead of one big one
150-
2. Avoid having index files in segments on layers that have slices.
154+
2. Avoid having index files in segments on layers that have slices.
151155
For example, if you have an index for the feature "comments", `📄 features/comments/index.js`, there's no reason to have another index for the `ui` segment of that feature, `📄 features/comments/ui/index.js`.
152-
3. If you have a very big project, there's a good chance that your application can be split into several big chunks.
156+
3. If you have a very big project, there's a good chance that your application can be split into several big chunks.
153157
For example, Google Docs has very different responsibilities for the document editor and for the file browser. You can create a monorepo setup where each package is a separate FSD root, with its own set of layers. Some packages can only have the Shared and Entities layers, others might only have Pages and App, others still might include their own small Shared, but still use the big one from another package too.
154158

155159
[import-rule-on-layers]: /docs/reference/layers#import-rule-on-layers

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

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

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

910
レイヤーは、Feature-Sliced Designにおける組織階層の最初のレベルです。その目的は、コードを責任の程度やアプリ内の他のモジュールへの依存度に基づいて分離することです。各レイヤーは、コードにどれだけの責任を割り当てるべきかを判断するための特別な意味を持っています。
1011

1112
合計で**7つのレイヤー**があり、責任と依存度が最も高いものから最も低いものへと配置されています。
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
15+
path={['/img/layers/folders-graphic-light.svg', '/img/layers/folders-graphic-dark.svg']}
16+
width="180"
17+
style={{ float: "right", margin: "0 1em" }}
18+
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."
19+
/>
1520

1621

1722
1. App (アップ)
@@ -51,9 +56,9 @@ AppとSharedのレイヤーは、このルールの**例外**です。これら
5156
このレイヤーで通常見られるセグメントは次のとおりです。
5257

5358
- `📁 api` — APIクライアントおよび特定のバックエンドエンドポイントへのリクエストを行う関数
54-
- `📁 ui` — アプリケーションのUIキット
59+
- `📁 ui` — アプリケーションのUIキット
5560
このレイヤーのコンポーネントはビジネスロジックを含むべきではありませんが、ビジネスに関連することは許可されています。例えば、会社のロゴやページレイアウトをここに置くことができます。UIロジックを持つコンポーネントも許可されています(例えば、オートコンプリートや検索バー)
56-
- `📁 lib` — 内部ライブラリのコレクション
61+
- `📁 lib` — 内部ライブラリのコレクション
5762
このフォルダーはヘルパーやユーティリティとして扱うべきではありません([なぜこれらのフォルダーがしばしばダンプに変わるか][ext-sova-utility-dump])。このフォルダー内の各ライブラリは、日付、色、テキスト操作など、1つの焦点を持つべきです。その焦点はREADMEファイルに文書化されるべきです。チームの開発者は、これらのライブラリに何を追加でき、何を追加できないかを知っているべきです
5863
- `📁 config` — 環境変数、グローバルフィーチャーフラグ、アプリの他のグローバル設定
5964
- `📁 routes` — ルート定数、またはルートをマッチさせるためのパターン

0 commit comments

Comments
 (0)