Skip to content

Commit 1e50bf5

Browse files
committed
Fix styling on QrCode component
1 parent cac6639 commit 1e50bf5

4 files changed

Lines changed: 69 additions & 28 deletions

File tree

_TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Hide any interactive or screen-specific components using display: none; in your
3434
- Navigation Menus: All top-level and dropdown links.
3535
- Search Icons/Bars: These are non-functional on paper.
3636
- Breadcrumbs: While useful on-screen for site hierarchy, they often look like cluttered, disconnected text on paper. Most designers remove them to keep the focus on the primary content.
37-
- Social Media & CTA Buttons: "Sign In" or "Follow Us" buttons are irrelevant in print.
37+
- Social Media & CTA Buttons & Download CTA: "Sign In" or "Follow Us" buttons are irrelevant in print.
3838

3939
__Expand External Links For Print__
4040

src/components/QrCode/server/index.ts

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { readFile } from 'node:fs/promises'
21
import QRCodeStyling from 'qr-code-styling'
32
import { JSDOM } from 'jsdom'
43

@@ -10,32 +9,67 @@ const QR_DOT_COLOR = '#000000'
109
const QR_CORNER_COLOR = '#4b5563'
1110
const QR_CORNER_DOT_COLOR = '#111111'
1211
const QR_BACKGROUND_COLOR = '#ffffff'
13-
const LOGO_OUTER_COLOR = '#000000'
14-
const LOGO_INNER_COLOR = '#6b7280'
1512
const LOGO_BACKDROP_COLOR = '#ffffff'
16-
const logoSvgFileUrl = new URL('../../../assets/images/site/logo.svg', import.meta.url)
17-
18-
let cachedLogoSvg: string | null = null
13+
const LOGO_SVG_MARKUP = `<svg
14+
id="logo"
15+
title="Webstack Builders Company Logo"
16+
width="88.360085"
17+
height="86.394562"
18+
viewBox="0 0 88.360085 86.394562"
19+
xmlns="http://www.w3.org/2000/svg"
20+
>
21+
<g
22+
id="logo-group"
23+
transform="translate(-64.234499,-91.339148)"
24+
>
25+
<path
26+
fill="#000000"
27+
id="logo-block-top-left"
28+
d="M 64.234499,105.965 V 91.339148 h 8.904504 8.904505 V 105.965 120.59085 h -8.904505 -8.904504 z"
29+
/>
30+
<path
31+
fill="#000000"
32+
id="logo-block-top-middle"
33+
d="M 88.893126,105.965 V 91.339148 H 109.0995 129.30588 V 105.965 120.59085 H 109.0995 88.893126 Z"
34+
/>
35+
<path
36+
fill="#000000"
37+
id="logo-block-top-right"
38+
d="M 134.78557,105.965 V 91.339148 h 8.90451 8.9045 V 105.965 120.59085 h -8.9045 -8.90451 z"
39+
/>
40+
<path
41+
fill="#6b7280"
42+
id="logo-block-middle-left"
43+
d="m 64.234499,134.53643 v -8.5034 h 20.548856 20.548855 v 8.5034 8.5034 H 84.783355 64.234499 Z"
44+
/>
45+
<path
46+
fill="#6b7280"
47+
id="logo-block-middle-right"
48+
d="m 111.49687,134.53643 v -8.5034 h 20.54885 20.54886 v 8.5034 8.5034 h -20.54886 -20.54885 z"
49+
/>
50+
<path
51+
fill="#000000"
52+
id="logo-block-bottom-left"
53+
d="m 64.234499,163.10786 v -14.62585 h 8.904504 8.904505 v 14.62585 14.62585 h -8.904505 -8.904504 z"
54+
/>
55+
<path
56+
fill="#000000"
57+
id="logo-block-bottom-middle"
58+
d="m 88.893126,163.10786 v -14.62585 h 20.206374 20.20638 v 14.62585 14.62585 H 109.0995 88.893126 Z"
59+
/>
60+
<path
61+
fill="#000000"
62+
id="logo-block-bottom-right"
63+
d="m 134.78557,163.10786 v -14.62585 h 8.90451 8.9045 v 14.62585 14.62585 h -8.9045 -8.90451 z"
64+
/>
65+
</g>
66+
</svg>`
1967

2068
export interface RenderQrCodeSvgOptions {
2169
data: string
2270
size?: number
2371
}
2472

25-
const getMonochromeLogoSvg = async (): Promise<string> => {
26-
if (cachedLogoSvg) {
27-
return cachedLogoSvg
28-
}
29-
30-
const logoSvg = await readFile(logoSvgFileUrl, 'utf8')
31-
32-
cachedLogoSvg = logoSvg
33-
.replace(/var\(--color-content-inverse\)/g, LOGO_OUTER_COLOR)
34-
.replace(/var\(--color-primary\)/g, LOGO_INNER_COLOR)
35-
36-
return cachedLogoSvg
37-
}
38-
3973
const parseLogoViewBox = (viewBox: null | string): { height: number; width: number } => {
4074
if (!viewBox) {
4175
return {
@@ -113,24 +147,22 @@ export const renderQrCodeSvg = async ({
113147
data,
114148
size = DEFAULT_SIZE,
115149
}: RenderQrCodeSvgOptions): Promise<string> => {
116-
const logoSvgMarkup = await getMonochromeLogoSvg()
117-
118150
const qrCode = new QRCodeStyling({
119151
backgroundOptions: {
120152
color: QR_BACKGROUND_COLOR,
121153
},
122154
cornersDotOptions: {
123155
color: QR_CORNER_DOT_COLOR,
124-
type: 'dot',
156+
type: 'dots',
125157
},
126158
cornersSquareOptions: {
127159
color: QR_CORNER_COLOR,
128-
type: 'extra-rounded',
160+
type: 'dots',
129161
},
130162
data,
131163
dotsOptions: {
132164
color: QR_DOT_COLOR,
133-
type: 'rounded',
165+
type: 'dots',
134166
},
135167
height: size,
136168
jsdom: JSDOM,
@@ -142,7 +174,7 @@ export const renderQrCodeSvg = async ({
142174
width: size,
143175
})
144176

145-
qrCode.applyExtension(createLogoExtension(logoSvgMarkup))
177+
qrCode.applyExtension(createLogoExtension(LOGO_SVG_MARKUP))
146178

147179
const svgBuffer = await qrCode.getRawData('svg')
148180

src/content/articles/demo/index.mdx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ isDraft: true
1212

1313
import decisionTreeDiagram from './decision-tree-for-page-vs-notification-classification.jpg'
1414
import Demo from '@components/Test/Demo.mdx'
15-
import QrCode from '@components/QrCode/index.astro'
1615

1716
Includes from [other Markdown]('/articles/demo') files.
1817

@@ -2171,6 +2170,14 @@ graph TD
21712170
D --> B
21722171
```
21732172

2173+
## QR Code
2174+
2175+
```markdown
2176+
<QrCode isHidden={false} data="https://www.webstackbuilders.com/articles/demo" />
2177+
```
2178+
2179+
<QrCode isHidden={false} data="https://www.webstackbuilders.com/articles/demo" />
2180+
21742181
## Social Embeds
21752182

21762183
### YouTube Embed

src/layouts/MarkdownLayout.astro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import List from '@components/List/index.astro'
3232
import ListItem from '@components/List/ListItem.astro'
3333
import MastodonModal from '@components/Social/Mastodon/index.astro'
3434
import Newsletter from '@components/CallToAction/Newsletter/index.astro'
35+
import QrCode from '@components/QrCode/index.astro'
3536
import Shares from '@components/Social/Shares/index.astro'
3637
import Table from '@components/Table/index.astro'
3738
import Time from '@components/Time/index.astro'
@@ -62,6 +63,7 @@ const Components = {
6263
MastodonModal,
6364
Newsletter,
6465
Picture,
66+
QrCode,
6567
Shares,
6668
Testimonials,
6769
Table,

0 commit comments

Comments
 (0)