Skip to content

Commit 98e81ee

Browse files
SnugugSam Richard
andauthored
🐛(site) Fix share overrides, small screen search, a2c langs (#765)
* Add share overrides for posts * Add proper lang attributes to badge generator Resolves #764 * Add a/button swap for small screen search Resolves #763 * Fix functions not working in vars * Made main a flex column * Make search wrapper grow-able * Make wrapper full-width --------- Co-authored-by: Sam Richard <samrichard@google.com>
1 parent bf3e563 commit 98e81ee

11 files changed

Lines changed: 88 additions & 10 deletions

File tree

site/lib/sanity/queries.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,18 @@ export const coreQuery = `
3737
'slug': slug.current
3838
},
3939
body,
40-
// share,
40+
share != null => {
41+
'share': {
42+
share.image.asset != null => {
43+
'image': {
44+
'image': 'cms://' + share.image.asset._ref,
45+
'alt': share.image.alt,
46+
},
47+
},
48+
'title': coalesce(share.title, title),
49+
'description':coalesce(share.description, description),
50+
}
51+
},
4152
tags[]->{
4253
title,
4354
'slug': slug.current

site/src/components/BadgeGenerator.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@
122122
class="badge-generator--radio-label"
123123
for="input-badge-{badge.id}"
124124
>
125-
<img src={badge.image} alt={badge.name} draggable="false" />
125+
<img
126+
src={badge.image}
127+
alt={badge.name}
128+
draggable="false"
129+
lang={language}
130+
/>
126131
<Generic
127132
cta={{
128133
type: 'low',
@@ -154,6 +159,7 @@
154159
<p
155160
class="badge-generator--attribution-text"
156161
dir={i18n.rtl ? 'rtl' : 'ltr'}
162+
lang={language}
157163
>
158164
{i18n.legal}
159165
</p>

site/src/components/SiteHeader.svelte

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@
8686

8787
<!-- Search Field -->
8888
<div class="header--search">
89+
<a href={`/${lang}/search`} aria-label="Search" class="header--search-link">
90+
<svg role="img" aria-hidden="true" class="icon">
91+
<use bind:this={searchIcon} href="/images/icons/sprite.svg#search" />
92+
</svg></a
93+
>
8994
<button class="header--search-toggle" on:click={toggleSearch}>
9095
<svg role="img" aria-hidden="true" class="icon">
9196
<use bind:this={searchIcon} href="/images/icons/sprite.svg#search" />
@@ -176,7 +181,8 @@
176181
}
177182
178183
&--menu,
179-
&--search-toggle {
184+
&--search-toggle,
185+
&--search-link {
180186
background: none;
181187
border: 0;
182188
padding: 0;
@@ -242,11 +248,22 @@
242248
}
243249
}
244250
251+
&--search-link {
252+
@media (min-width: 535px) {
253+
display: none;
254+
}
255+
}
256+
245257
&--search-toggle {
258+
display: none;
246259
width: 2rem;
247260
margin-inline-start: auto;
248261
padding-inline-end: 0.25rem;
249262
263+
@media (min-width: 535px) {
264+
display: block;
265+
}
266+
250267
[data-active-search] & {
251268
background-color: var(--grey-100);
252269
}

site/src/layouts/article.astro

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
2+
import type { Share } from '$types/sanity';
3+
24
import Wrapper from '$layouts/wrapper.astro';
35
import Recommended from '$components/Recommended.svelte';
46
@@ -10,13 +12,20 @@ export interface Props {
1012
content: string;
1113
}>;
1214
microcopy: object;
15+
share?: Share;
1316
}
1417
15-
const { title, props = [], metadesc, microcopy } = Astro.props;
18+
const { title, props = [], metadesc, microcopy, share } = Astro.props;
1619
const { locale } = microcopy;
1720
---
1821

19-
<Wrapper title={title} metadesc={metadesc} locale={locale} props={props}>
22+
<Wrapper
23+
title={title}
24+
metadesc={metadesc}
25+
locale={locale}
26+
props={props}
27+
share={share}
28+
>
2029
<article class="article">
2130
<div class="article--header">
2231
<slot name="header" />

site/src/layouts/wrapper.astro

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
22
import type { Locale } from '$types/content';
3+
import type { Share } from '$types/sanity';
4+
35
import { pwaInfo } from 'virtual:pwa-info';
46
import SiteHeader from '$components/SiteHeader.svelte';
57
import Announcement from '$components/Announcement.astro';
@@ -19,9 +21,10 @@ export interface Props {
1921
content: string;
2022
}>;
2123
locale: Locale;
24+
share?: Share;
2225
}
2326
24-
const { title, props = [], locale, metadesc } = Astro.props;
27+
const { title, props = [], locale, metadesc, share } = Astro.props;
2528
2629
// TODO: get all availabe languages for current content
2730
const languages = [];
@@ -70,6 +73,22 @@ const t =
7073
{pwaInfo && <Fragment set:html={pwaInfo.webManifest.linkTag} />}
7174
<link rel="icon" type="image/png" href="ix://icons/favicon.png" />
7275
<link rel="apple-touch-icon" href="/images/icons/pwa/icon-192x192.png" />
76+
<!-- Open Graph -->
77+
{
78+
share && (
79+
<>
80+
<meta property="og:title" content={share.title} />
81+
<meta property="og:description" content={share.description} />
82+
{share.image && (
83+
<>
84+
<meta property="og:image" content={share.image.image} />
85+
<meta property="og:image:alt" content={share.image.alt} />
86+
</>
87+
)}
88+
</>
89+
)
90+
}
91+
<meta property="og:url" content={l10nURL(Astro.url, locale.code)} />
7392
{
7493
props.map((prop) => {
7594
return <meta property={`og:${prop.property}`} content={prop.content} />;

site/src/pages/[lang]/posts/[page].astro

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { posts, microcopy as micro } from '$lib/sanity';
99
import type { PostHeroProps } from '$components/PostHero.svelte';
1010
import Text from '$components/Text.astro';
1111
import { buildTOC } from '$lib/portabletext';
12-
import type { Microcopy } from '$types/sanity';
12+
import type { Microcopy, Share } from '$types/sanity';
1313
1414
/**
1515
* Builds paths for news pagination
@@ -71,9 +71,15 @@ const authors = {
7171
};
7272
7373
const toc = buildTOC(post.body);
74+
const share = (post.share as Share) || null;
7475
---
7576

76-
<Article title={post.title} metadesc={post.description} microcopy={microcopy}>
77+
<Article
78+
title={post.title}
79+
metadesc={post.description}
80+
microcopy={microcopy}
81+
share={share}
82+
>
7783
<Fragment slot="header">
7884
<PostHero {...hero} />
7985
</Fragment>

site/src/pages/[lang]/search.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const { locale } = microcopy;
4949
<style lang="scss">
5050
.wrapper {
5151
background-color: var(--grey-100);
52-
min-height: 100%;
52+
flex-grow: 1;
5353
}
5454

5555
.search-wrapper {

site/src/sass/_shared.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// Globals
55
@import 'globals/colors';
6-
@import 'globals/vars';
76
@import 'globals/functions';
7+
@import 'globals/vars';
88
@import 'globals/mixins';
99
@import 'globals/extends';

site/src/sass/components/_body.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@ body {
3535
.main {
3636
flex: 1 0 auto;
3737
height: max-content;
38+
display: flex;
39+
flex-direction: column;
3840
}

site/src/sass/components/_wrapper.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
height: auto;
1313
margin: math.div($wrapper-block-spacing-m, 2) auto;
14+
width: 100%;
1415
max-width: $wrapper-content-max-width;
1516

1617
@supports (margin: clamp(1px, 1vw, 2px)) {

0 commit comments

Comments
 (0)