Skip to content

Commit e4bebac

Browse files
authored
refactor: use Astro image optimization (#34)
1 parent 03accc2 commit e4bebac

25 files changed

+98
-55
lines changed

docs/CONTRIBUTING-WIKI.md

+38-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The various components available for use can be found in [`src/components/common
66

77
## Article Frontmatter
88

9-
All wiki articles can contain frontmatter at the top of the file.
9+
All wiki articles must contain some frontmatter at the top of the file.
1010

1111
| Property | Type | Required | Descripion |
1212
| :-------------: | :--------: | :------: | --------------------------------------------------------------------------------------------------------------------------- |
@@ -23,3 +23,40 @@ description: Wow, my own article, cool!
2323
incomplete: true
2424
---
2525
```
26+
27+
## Images
28+
29+
The way images are handled in Astro is slightly odd, but it does come with some nice benefits.
30+
31+
### Remote Images
32+
33+
Remote images can simply be linked to like standard markdown:
34+
35+
```md
36+
![Alt text is important!](https://avatars.githubusercontent.com/u/124349233)
37+
```
38+
39+
### Local Images
40+
41+
Unless there is a good reason for an image to be [permanently and publically linkable](#public-images), images should saved to `src/assets/images/` and loaded like so:
42+
43+
```astro
44+
![A cat walking](~/assets/images/cat.png)
45+
```
46+
47+
In some rare cases, they may have to be manually imported and loaded using the `<Image>` or other component:
48+
49+
```astro
50+
import { Image } from "astro:assets";
51+
import dog from "~/assets/images/dog.png";
52+
53+
<Image src={dog} alt="A dog sitting" />
54+
```
55+
56+
### Public Images
57+
Images that need to be publically available, say for serving to other software, or for linking to other websites, need to be saved to `public/images/`. They can then be used just like [local images](#local-images), but the file path is instead relative to the public directory:
58+
59+
```diff
60+
- ![A cat walking](~/assets/images/cat.png)
61+
+ ![A cat walking](/images/cat.png)
62+
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/components/common/Tabs.astro

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import type { XOR } from "~/util/types";
33
import Icon from "./Icon.astro";
44
import jsdom from "jsdom";
5+
import { Image } from "astro:assets";
56
67
type BaseButtonDefinition = {
78
name: string;
@@ -10,7 +11,7 @@ type BaseButtonDefinition = {
1011
1112
type ButtonDefinition = XOR<
1213
BaseButtonDefinition & { icon: string },
13-
BaseButtonDefinition & { image: string }
14+
BaseButtonDefinition & { image: ImageMetadata }
1415
>;
1516
1617
export interface Props {
@@ -41,7 +42,7 @@ body.querySelector(`[data-tab="${active}"]`)?.classList.add("active");
4142
style={`--accent-color: ${button.accent ?? "#ffffff"}`}
4243
>
4344
<span>
44-
{button.image && <img src={button.image} />}
45+
{button.image && <Image src={button.image} alt={button.name}/>}
4546
{button.icon && <Icon name={button.icon} group="solid" />}
4647
{button.name}
4748
</span>

src/components/wiki/Image.astro

-12
This file was deleted.

src/components/wiki/README.md

-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,5 @@ Used to display the priority level of the diagnostic next to its heading.
1010
## [Heading](./Heading.astro)
1111
Extends the default heading HTML element to have an anchor pointing to them, for ease of copying the URL to a specific heading.
1212

13-
## [Image](./Image.astro)
14-
Wraps the default `<img>` HTML element so that images can be lazy loaded.
15-
1613
## [WikiLink](./WikiLink.astro)
1714
Either renders a normal link when linking somewhere in the same local domain or an [ExternalLink](../common/ExternalLink.astro) when linking externally.

src/content/wiki/annotations.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ The below methods can be added to the end of a line:
4949
## Tips
5050

5151
- If you type `---` one line above a function, you will receive a suggested snippet that includes [`@param`](#param) and [`@return`](#return) annotations for each parameter and return value found in the function.
52-
![Snippet being used in VS Code](/images/wiki/annotation-snippet.png)
52+
![Snippet being used in VS Code](~/assets/images/wiki/annotation-snippet.png)
5353

5454
## Documenting Types
5555

src/content/wiki/build.mdx

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ getting-started: true
77
import Tabs from "~/components/common/Tabs.astro";
88
import Remark from "~/components/common/Remark.astro";
99

10+
import windowsImg from "~/assets/images/windows.svg"
11+
import macImg from "~/assets/images/mac.svg"
12+
import linuxImg from "~/assets/images/linux.svg"
13+
1014
1. Install [Ninja](https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages)
1115
2. Ensure you have C++17
1216
3. Clone the language server
@@ -19,9 +23,9 @@ import Remark from "~/components/common/Remark.astro";
1923
<Tabs
2024
active="Windows"
2125
buttons={[
22-
{ name: "Windows", image: "/images/windows.svg", accent: "#23a9f2" },
23-
{ name: "MacOS", image: "/images/mac.svg", accent: "#ffffff" },
24-
{ name: "Linux", image: "/images/linux.svg", accent: "#ffff00" },
26+
{ name: "Windows", image: windowsImg, accent: "#23a9f2" },
27+
{ name: "MacOS", image: macImg, accent: "#ffffff" },
28+
{ name: "Linux", image: linuxImg, accent: "#ffff00" },
2529
]}
2630
>
2731
{/* prettier-ignore */}

src/content/wiki/developing.mdx

+7-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import Remark from "~/components/common/Remark.astro";
88
import Accordion from "~/components/common/Accordion.astro";
99
import FileTreeItem from "~/components/common/FileTreeItem.astro";
1010

11+
import windowsImg from "~/assets/images/windows.svg"
12+
import macImg from "~/assets/images/mac.svg"
13+
import linuxImg from "~/assets/images/linux.svg"
14+
1115
Thank you for taking an interest in helping improve the language server!
1216

1317
## Debugging
@@ -55,9 +59,9 @@ You will need two Visual Studio Code instances open:
5559
<Tabs
5660
active="Windows"
5761
buttons={[
58-
{ name: "Windows", image: "/images/windows.svg", accent: "#23a9f2" },
59-
{ name: "MacOS", image: "/images/mac.svg", accent: "#ffffff" },
60-
{ name: "Linux", image: "/images/linux.svg", accent: "#ffff00" },
62+
{ name: "Windows", image: windowsImg, accent: "#23a9f2" },
63+
{ name: "MacOS", image: macImg, accent: "#ffffff" },
64+
{ name: "Linux", image: linuxImg, accent: "#ffff00" },
6165
]}
6266
>
6367
<div data-tab="Windows">`%USERPROFILE%\.vscode\extensions\sumneko.lua-VERSION\server`</div>

src/content/wiki/export-docs.mdx

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ description: The language server can export documentation for your project in Ma
66
import Accordion from "~/components/common/Accordion.astro";
77
import Tabs from "~/components/common/Tabs.astro";
88

9+
import vscodeImg from "~/assets/images/vscode.svg"
10+
911
## Example
1012

1113
<Accordion>
@@ -251,7 +253,7 @@ import Tabs from "~/components/common/Tabs.astro";
251253
<Tabs
252254
active="VS Code"
253255
buttons={[
254-
{ name: "VS Code", image: "/images/vscode.svg", accent: "#23a9f2" },
256+
{ name: "VS Code", image: vscodeImg, accent: "#23a9f2" },
255257
{ name: "Other", icon: "question", accent: "#ff158e" },
256258
]}
257259
>

src/content/wiki/faq.mdx

+9-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import AccordionGroup from "~/components/common/AccordionGroup.astro";
99
import Tabs from "~/components/common/Tabs.astro";
1010
import Remark from "~/components/common/Remark.astro";
1111

12+
import vscodeImg from "~/assets/images/vscode.svg"
13+
import windowsImg from "~/assets/images/windows.svg"
14+
import wslImg from "~/assets/images/wsl.svg"
15+
import linuxImg from "~/assets/images/linux.svg"
16+
1217
<AccordionGroup>
1318
<Accordion>
1419
<span slot="summary">
@@ -20,17 +25,17 @@ For debugging and a more detailed log file, you can add [`--loglevel=trace`](/wi
2025
<Tabs
2126
active="VS Code"
2227
buttons={[
23-
{ name: "VS Code", image: "/images/vscode.svg", accent: "#23a9f2" },
28+
{ name: "VS Code", image: vscodeImg, accent: "#23a9f2" },
2429
{ name: "Other", icon: "question", accent: "#ff158e" },
2530
]}
2631
>
2732
<div data-tab="VS Code">
2833
<Tabs
2934
active="Windows"
3035
buttons={[
31-
{ name: "Windows", image: "/images/windows.svg", accent: "#23a9f2" },
32-
{ name: "WSL", image: "/images/wsl.svg", accent: "#ffffff" },
33-
{ name: "Linux/MacOS", image: "/images/linux.svg", accent: "#ffff00" },
36+
{ name: "Windows", image: windowsImg, accent: "#23a9f2" },
37+
{ name: "WSL", image: wslImg, accent: "#ffffff" },
38+
{ name: "Linux/MacOS", image: linuxImg, accent: "#ffff00" },
3439
]}
3540
>
3641
<div data-tab="Windows">

src/content/wiki/formatter.mdx

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ getting-started: true
77
import Remark from "~/components/common/Remark.astro";
88
import Tabs from "~/components/common/Tabs.astro";
99

10+
import jsonImg from "~/assets/images/json.svg"
11+
import luaImg from "~/assets/images/lua.svg"
12+
1013
The language server has a built-in code formatter, courtesy of [`CppCXY/EmmyLuaCodeStyle`](https://github.com/CppCXY/EmmyLuaCodeStyle), that allows you to easily format your code. It also offers [code style checking](#code-style-checking)
1114

1215
<Remark type="note">
@@ -29,8 +32,8 @@ To set a default global configuration across projects, navigate to your [configu
2932
<Tabs
3033
active="JSON"
3134
buttons={[
32-
{ name: "JSON", image: "/images/json.svg", accent: "#959595" },
33-
{ name: "Lua", image: "/images/lua.svg", accent: "#000080" },
35+
{ name: "JSON", image: jsonImg, accent: "#959595" },
36+
{ name: "Lua", image: luaImg, accent: "#000080" },
3437
]}
3538
>
3639
<div data-tab="JSON">

src/content/wiki/usage.mdx

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@ getting-started: true
77
import Tabs from "~/components/common/Tabs.astro";
88
import Remark from "~/components/common/Remark.astro";
99

10+
import windowsImg from "~/assets/images/windows.svg"
11+
import macImg from "~/assets/images/mac.svg"
12+
import linuxImg from "~/assets/images/linux.svg"
13+
1014
## Run
1115

1216
The language server can be run using the below command:
1317

1418
<Tabs
1519
active="Windows"
1620
buttons={[
17-
{ name: "Windows", image: "/images/windows.svg", accent: "#23a9f2" },
18-
{ name: "MacOS", image: "/images/mac.svg", accent: "#ffffff" },
19-
{ name: "Linux", image: "/images/linux.svg", accent: "#ffff00" },
21+
{ name: "Windows", image: windowsImg, accent: "#23a9f2" },
22+
{ name: "MacOS", image: macImg, accent: "#ffffff" },
23+
{ name: "Linux", image: linuxImg, accent: "#ffff00" },
2024
]}
2125
>
2226
{/* prettier-ignore */}
@@ -41,7 +45,7 @@ The language server can be run using the below command:
4145

4246
<Remark type="note">
4347
If you use the Visual Studio Code extension, the language server is run for
44-
you. Arguments and flags be used by adding them to the
48+
you. Arguments and flags can be used by adding them to the
4549
[`misc.parameters`](/wiki/settings#miscparameters) setting.
4650
</Remark>
4751

src/pages/index.astro

+13-8
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ import ExternalLink from "../components/common/ExternalLink.astro";
44
import Icon from "../components/common/Icon.astro";
55
import CodeBlock from "../components/common/CodeBlock.astro";
66
import Remark from "../components/common/Remark.astro";
7+
import Tooltip from "../components/common/Tooltip.astro";
8+
9+
import { Image } from "astro:assets";
10+
import vsCodeImg from "~/assets/images/vscode.svg";
11+
import neovimImg from "~/assets/images/neovim.svg";
712
813
import "../scss/fonts/_Prompt.scss";
9-
import Tooltip from "../components/common/Tooltip.astro";
1014
1115
const annotationsPage = await import("~/content/wiki/annotations.mdx");
1216
const annotationCount = annotationsPage
@@ -24,7 +28,7 @@ const annotationCount = annotationsPage
2428
<Tooltip content="Unique installs in Visual Studio Code">
2529
<span class="stat installs">
2630
<b>1M+</b>
27-
<img src="/images/vscode.svg" alt="Visual Studio Code installs" />
31+
<Image src={vsCodeImg} alt="Visual Studio Code installs" />
2832
</span>
2933
</Tooltip>
3034
<Tooltip content="Stars on GitHub">
@@ -157,12 +161,12 @@ const annotationCount = annotationsPage
157161
<section id="install">
158162
<h2>Install for...</h2>
159163
<div class="install-tabs">
160-
<button value="vscode-install" class="vscode active" tabindex="0"
161-
><img src="/images/vscode.svg" alt="Visual Studio Code" /></button
162-
>
163-
<button value="neovim-install" class="neovim" tabindex="0"
164-
><img src="/images/neovim.svg" alt="Neovim" /></button
165-
>
164+
<button value="vscode-install" class="vscode active" tabindex="0">
165+
<Image src={vsCodeImg} alt="Visual Studio Code" />
166+
</button>
167+
<button value="neovim-install" class="neovim" tabindex="0">
168+
<Image src={neovimImg} alt="Neovim" />
169+
</button>
166170
<button value="other-install" class="other" tabindex="0"
167171
><Icon name="question" group="solid" /></button
168172
>
@@ -526,6 +530,7 @@ exec &quot;&lt;path-to-directory&gt;/bin/lua-language-server&quot; &quot;$@&quot
526530

527531
img {
528532
width: 1.4em;
533+
height: auto;
529534
}
530535
}
531536
}

src/pages/wiki/[...slug].astro

-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import H3 from "~/components/wiki/headings/H3.astro";
1111
import H4 from "~/components/wiki/headings/H4.astro";
1212
import H5 from "~/components/wiki/headings/H5.astro";
1313
import H6 from "~/components/wiki/headings/H6.astro";
14-
import Image from "~/components/wiki/Image.astro";
1514
import dayjs from "~/services/time";
1615
import Tooltip from "~/components/common/Tooltip.astro";
1716
@@ -48,7 +47,6 @@ const modifiedTime = remarkPluginFrontmatter.lastModified
4847
h4: H4,
4948
h5: H5,
5049
h6: H6,
51-
img: Image,
5250
}}
5351
/>
5452
<div class="modified-timestamp">

src/pages/wiki/index.astro

+4-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import Tooltip from "~/components/common/Tooltip.astro";
66
import fetch from "~/util/fetch";
77
import ExternalLink from "~/components/common/ExternalLink.astro";
88
9+
import { Image } from "astro:assets";
10+
911
const CONTRIBUTOR_COUNT = 30;
1012
1113
const allWikiArticles = await getCollection("wiki");
@@ -117,7 +119,7 @@ if (!contributors) {
117119
rel="noopener nofollow"
118120
target="_blank"
119121
>
120-
<img src={user.avatar_url} />
122+
<Image src={user.avatar_url} alt={user.login} inferSize />
121123
</a>
122124
<Tooltip
123125
content={user.login}
@@ -201,14 +203,6 @@ if (!contributors) {
201203
margin: 0px 1em;
202204
}
203205

204-
:global(div.contributor.placeholder) {
205-
--tier-color: #fff;
206-
207-
:global(img) {
208-
border: none;
209-
}
210-
}
211-
212206
div.contributor {
213207
height: auto;
214208
width: 100%;
@@ -218,6 +212,7 @@ if (!contributors) {
218212
display: block;
219213
aspect-ratio: 1;
220214
width: 100%;
215+
height: auto;
221216
border-radius: 99em;
222217
&:focus {
223218
outline: var(--tier-color) solid 0.3em;

0 commit comments

Comments
 (0)