Skip to content

Commit 10a43e2

Browse files
authored
chore: Misc cleaning (#1349)
* refactor: Move branding config into branding widget * refactor: Remove unused code paths in content-region * refactor: Lazy load images by default * chore: Fix broken types as of v11
1 parent fc6cdb3 commit 10a43e2

7 files changed

Lines changed: 25 additions & 127 deletions

File tree

plugins/precompile-markdown/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ marked.use({
9696
return `<a href="${href}">${text}</a>`;
9797
},
9898
image({ href, text }) {
99-
return `<img decoding="async" src="${href}" alt="${text}" />`;
99+
return `<img loading="lazy" decoding="async" src="${href}" alt="${text}" />`;
100100
},
101101
code({ text, lang }) {
102102
const [code, source, runInRepl] = processRepl(text.trim());

src/components/branding/index.jsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
import style from './style.module.css';
2-
import config from '../../config.json';
2+
3+
const LOGOS = [
4+
{
5+
name: 'logo-text',
6+
alt: 'Full Logo'
7+
},
8+
{
9+
name: 'logo-text-inverted',
10+
alt: 'Full Logo with Inverted Colors'
11+
},
12+
{
13+
name: 'symbol',
14+
alt: 'Preact Symbol'
15+
},
16+
{
17+
name: 'symbol-inverted',
18+
alt: 'Preact Symbol with Inverted Colors'
19+
}
20+
];
321

422
export default function Branding() {
523
return (
624
<div class={style.logos}>
7-
{config.branding.map(asset => (
25+
{LOGOS.map(asset => (
826
<LogoVariation name={asset.name} alt={asset.alt} />
927
))}
1028
</div>
Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,13 @@
11
import { useEffect } from 'preact/hooks';
22
import Markup from 'preact-markup';
33
import widgets from '../widgets';
4-
import style from './style.module.css';
5-
import { useTranslation } from '../../lib/i18n';
64
import { TocContext } from '../table-of-contents';
75

86
const COMPONENTS = {
97
...widgets
108
};
119

12-
function SiblingNav({ route, lang, start }) {
13-
let title = '';
14-
let url = '';
15-
if (route) {
16-
url = route.path.toLowerCase();
17-
title =
18-
typeof route.name === 'object'
19-
? route.name[lang || 'en']
20-
: route.name || route.title;
21-
}
22-
const label = useTranslation(start ? 'previous' : 'next');
23-
24-
return (
25-
<a class={style.nextLink} data-dir-end={!start} href={url}>
26-
{start && <span class={style.icon}>&larr;&nbsp;</span>}
27-
{!start && <span class={style.icon}>&nbsp;&rarr;</span>}
28-
<span class={style.nextInner}>
29-
<span class={style.nextTitle}>
30-
<span class={style.nextTitleInner}>{title}</span>
31-
</span>
32-
<span class={style.nextUrl}>{label}</span>
33-
</span>
34-
</a>
35-
);
36-
}
37-
3810
export default function ContentRegion({ content, components, ...props }) {
39-
const hasNav = !!(props.next || props.prev);
4011
components = Object.assign({}, COMPONENTS, components);
4112

4213
useEffect(() => {
@@ -49,11 +20,7 @@ export default function ContentRegion({ content, components, ...props }) {
4920
}, [props.current]);
5021

5122
return (
52-
<content-region
53-
name={props.current}
54-
data-page-nav={hasNav}
55-
can-edit={props.canEdit}
56-
>
23+
<content-region name={props.current} can-edit={props.canEdit}>
5724
{content && (
5825
<TocContext.Provider value={{ toc: props.toc }}>
5926
<Markup
@@ -64,20 +31,6 @@ export default function ContentRegion({ content, components, ...props }) {
6431
/>
6532
</TocContext.Provider>
6633
)}
67-
{hasNav && (
68-
<div class={style.nextWrapper}>
69-
{props.prev ? (
70-
<SiblingNav start lang={props.lang} route={props.prev} />
71-
) : (
72-
<span />
73-
)}
74-
{props.next ? (
75-
<SiblingNav lang={props.lang} route={props.next} />
76-
) : (
77-
<span />
78-
)}
79-
</div>
80-
)}
8134
</content-region>
8235
);
8336
}

src/components/content-region/style.module.css

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/components/header/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function NavMenu(props) {
223223
/**
224224
* Button that expands into a menu when clicked. Pass in label & menu items as children.
225225
*
226-
* @param {ExpandableNavLinkProps & import('preact').JSX.ButtonHTMLAttributes} props
226+
* @param {ExpandableNavLinkProps & import('preact').ButtonHTMLAttributes} props
227227
*/
228228
function ExpandableNavLink({ isOpen, label, children, ...rest }) {
229229
return (
@@ -247,7 +247,7 @@ function ExpandableNavLink({ isOpen, label, children, ...rest }) {
247247
*/
248248

249249
/**
250-
* @param {NavLinkProps & import('preact').AnchorHTMLAttributes} props
250+
* @param {NavLinkProps & Omit<import('preact').AnchorHTMLAttributes, 'role'>} props
251251
*/
252252
function NavLink({ href, flair, clsx, isOpen, ...rest }) {
253253
const { path } = useLocation();

src/config.json

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,23 +1092,5 @@
10921092
"en": "Congratulations!"
10931093
}
10941094
}
1095-
],
1096-
"branding": [
1097-
{
1098-
"name": "logo-text",
1099-
"alt": "Full Logo"
1100-
},
1101-
{
1102-
"name": "logo-text-inverted",
1103-
"alt": "Full Logo with Inverted Colors"
1104-
},
1105-
{
1106-
"name": "symbol",
1107-
"alt": "Preact Symbol"
1108-
},
1109-
{
1110-
"name": "symbol-inverted",
1111-
"alt": "Preact Symbol with Inverted Colors"
1112-
}
11131095
]
11141096
}

src/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ declare global {
44
namespace preact.JSX {
55
interface IntrinsicElements {
66
'loading-bar': { showing: boolean };
7-
'content-region': { name: string; 'data-page-nav': boolean; 'can-edit': boolean, children: any };
7+
'content-region': { name: string; 'can-edit': boolean, children: any };
88
}
99
}
1010
}

0 commit comments

Comments
 (0)