Skip to content

Commit 459b0ef

Browse files
committed
Pull in the text balancer from our static host
1 parent bb902d9 commit 459b0ef

6 files changed

Lines changed: 70 additions & 24 deletions

File tree

website/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules/
22
public/
33
static/fonts/
44
static/syntax-highlighting.css
5+
static/text-balancer.js

website/content/_index.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ title = "Free online vector editor & procedural design tool"
33
template = "section.html"
44

55
[extra]
6-
css = ["/page/index.css", "/component/carousel.css", "/component/feature-icons.css", "/component/feature-box.css", "/component/youtube-embed.css", "/layout/balance-text.css"]
6+
css = ["/page/index.css", "/component/carousel.css", "/component/feature-icons.css", "/component/feature-box.css", "/component/youtube-embed.css"]
77
js = ["/js/carousel.js", "/js/youtube-embed.js", "/js/video-autoplay.js"]
8-
linked_js = ["https://static.graphite.rs/text-balancer/text-balancer.js"]
8+
linked_js = []
99
meta_description = "Open source free software. A vector graphics creativity suite with a clean, intuitive interface. Opens instantly (no signup) and runs locally in a browser. Exports SVG, PNG, JPG."
1010
+++
1111

12+
<!-- replacements::text_balancer() -->
13+
1214
<!-- ▛ LOGO ▜ -->
1315
<section id="logo">
1416
<div class="block">

website/install-fonts.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const fs = require("fs");
2+
const https = require("https");
23
const path = require("path");
34

45
// Define basePath
@@ -155,3 +156,39 @@ if (unusedFiles.length > 0) {
155156
}
156157

157158
console.log("\nFont installation complete!");
159+
160+
// Fetch and save text-balancer.js, which we don't commit to the repo so we're not version controlling dependency code
161+
const textBalancerUrl = "https://static.graphite.rs/text-balancer/text-balancer.js";
162+
const textBalancerDest = path.join(basePath, "static", "text-balancer.js");
163+
console.log("\nDownloading text-balancer.js...");
164+
https
165+
.get(textBalancerUrl, (res) => {
166+
if (res.statusCode !== 200) {
167+
console.error(`Failed to download text-balancer.js. Status code: ${res.statusCode}`);
168+
res.resume();
169+
return;
170+
}
171+
172+
let data = "";
173+
res.on("data", (chunk) => {
174+
data += chunk;
175+
});
176+
177+
res.on("end", () => {
178+
try {
179+
// Ensure destination directory exists
180+
const destDir = path.dirname(textBalancerDest);
181+
if (!fs.existsSync(destDir)) {
182+
fs.mkdirSync(destDir, { recursive: true });
183+
console.log(`Created directory: ${destDir}`);
184+
}
185+
fs.writeFileSync(textBalancerDest, data, "utf8");
186+
console.log(`Downloaded and saved: ${textBalancerDest}`);
187+
} catch (error) {
188+
console.error(`Error saving text-balancer.js:`, error);
189+
}
190+
});
191+
})
192+
.on("error", (err) => {
193+
console.error(`Error downloading text-balancer.js:`, err);
194+
});

website/sass/layout/balance-text.scss

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

website/templates/base.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@
124124
</header>
125125
<main>
126126
{%- filter replace(from = "<!-- replacements::blog_posts(count = 2) -->", to = replacements::blog_posts(count = 2)) -%}
127+
{%- filter replace(from = "<!-- replacements::text_balancer() -->", to = replacements::text_balancer()) -%}
127128
{%- block content -%}{%- endblock -%}
128129
{%- endfilter -%}
130+
{%- endfilter -%}
129131
</main>
130132
<footer>
131133
<hr />

website/templates/macros/replacements.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,29 @@ <h2 class="headline"><a href="{{ article.permalink | safe }}">{{ article.title }
1212
</div>
1313
{% endfor %}
1414
{% endmacro blog_posts %}
15+
16+
{% macro text_balancer() %}
17+
<style>
18+
.balance-text {
19+
visibility: hidden;
20+
}
21+
22+
@media (scripting: none) {
23+
.balance-text {
24+
visibility: visible !important;
25+
}
26+
}
27+
28+
@supports (text-wrap: balance) {
29+
.balance-text,
30+
.balanced-text {
31+
text-align: left;
32+
text-wrap: balance;
33+
visibility: visible;
34+
}
35+
}
36+
</style>
37+
<script>
38+
{{ load_data(path="static/text-balancer.js", format="plain") | safe }}
39+
</script>
40+
{% endmacro text_balancer %}

0 commit comments

Comments
 (0)