Skip to content

Commit b59f24a

Browse files
committed
formatting frontend assets
1 parent 237668f commit b59f24a

File tree

9 files changed

+128
-151
lines changed

9 files changed

+128
-151
lines changed

.vscode/extensions.json

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

55
// List of extensions which should be recommended for users of this workspace.
66
"recommendations": [
7+
"esbenp.prettier-vscode",
78
"julialang.language-julia",
89
],
910
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.

.vscode/settings.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,21 @@
22
"files.associations": {
33
"*.jlmd": "markdown",
44
"*.jlhtml": "html",
5+
},
6+
7+
"prettier.printWidth": 160,
8+
"prettier.tabWidth": 4,
9+
"prettier.semi": false,
10+
"prettier.quoteProps": "consistent",
11+
"prettier.singleQuote": false,
12+
13+
"editor.formatOnSave": false,
14+
"[javascript]": {
15+
"editor.defaultFormatter": "esbenp.prettier-vscode",
16+
"editor.formatOnSave": true
17+
},
18+
"[css]": {
19+
"editor.defaultFormatter": "esbenp.prettier-vscode",
20+
"editor.formatOnSave": true
521
}
622
}

src/assets/scripts/search.js

Lines changed: 57 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
const root_href = document.head.querySelector("link[rel='root']").getAttribute('href')
1+
const root_href = document.head.querySelector("link[rel='root']").getAttribute("href")
22

3-
4-
const minby = (arr, fn) => arr.reduce((a, b) => fn(a) < fn(b) ? a : b)
5-
const maxby = (arr, fn) => arr.reduce((a, b) => fn(a) > fn(b) ? a : b)
3+
const minby = (arr, fn) => arr.reduce((a, b) => (fn(a) < fn(b) ? a : b))
4+
const maxby = (arr, fn) => arr.reduce((a, b) => (fn(a) > fn(b) ? a : b))
65
const range = (length) => [...Array(length).keys()]
76

87
const sortby = (arr, fn) => arr.sort((a, b) => fn(a) - fn(b))
98

10-
119
const setup_search_index = async () => {
12-
const search_data_href = document.head.querySelector("link[rel='pp-search-data']").getAttribute('href')
10+
const search_data_href = document.head.querySelector("link[rel='pp-search-data']").getAttribute("href")
1311
console.log(search_data_href)
14-
12+
1513
const search_data = await (await fetch(search_data_href)).json()
1614
window.search_data = search_data
17-
15+
1816
console.log(search_data)
1917

2018
// create a search bar powered by lunr
@@ -29,50 +27,46 @@ const setup_search_index = async () => {
2927
// create a search index
3028
const before = Date.now()
3129
const search_index = window.lunr(function () {
32-
this.ref('url')
33-
34-
this.field('title', { boost: 10 })
35-
this.field('tags', { boost: 5 })
36-
this.field('text')
37-
this.metadataWhitelist = ['position']
30+
this.ref("url")
31+
32+
this.field("title", { boost: 10 })
33+
this.field("tags", { boost: 5 })
34+
this.field("text")
35+
this.metadataWhitelist = ["position"]
3836
search_data.forEach(function (doc) {
3937
this.add(doc)
4038
}, this)
4139
})
4240
const after = Date.now()
4341
console.info(`lunr: Indexing ${search_data.length} documents took ${after - before}ms`)
4442
window.search_index = search_index
45-
46-
return {search_data, search_index}
47-
}
4843

44+
return { search_data, search_index }
45+
}
4946

5047
const excerpt_length = 200
5148
const excerpt_padding = 50
5249

53-
5450
const init_search = async () => {
55-
const query = new URLSearchParams(window.location.search).get('q')
56-
console.warn({query})
57-
51+
const query = new URLSearchParams(window.location.search).get("q")
52+
console.warn({ query })
53+
5854
document.querySelector(".search-bar.big input").value = query
59-
60-
const {search_data, search_index} = await setup_search_index()
61-
55+
56+
const { search_data, search_index } = await setup_search_index()
57+
6258
if (query) {
6359
const results = search_index.search(query)
6460
console.log(results)
65-
66-
const search_results = document.getElementById('search-results')
67-
68-
if(results.length !== 0) {
69-
70-
71-
search_results.innerHTML = ''
72-
results.forEach(result => {
73-
const {url, title, tags, text} = search_data.find(doc => doc.url === result.ref)
74-
const result_div = document.createElement('a')
75-
result_div.classList.add('search-result')
61+
62+
const search_results = document.getElementById("search-results")
63+
64+
if (results.length !== 0) {
65+
search_results.innerHTML = ""
66+
results.forEach((result) => {
67+
const { url, title, tags, text } = search_data.find((doc) => doc.url === result.ref)
68+
const result_div = document.createElement("a")
69+
result_div.classList.add("search-result")
7670
result_div.innerHTML = `
7771
<h3 class="title"></h3>
7872
<p class="snippet"></p>
@@ -81,85 +75,74 @@ const init_search = async () => {
8175
console.log(root_href)
8276
result_div.querySelector(".title").innerText = title
8377
result_div.href = new URL(url, new URL(root_href, window.location.href)).href
84-
result_div.querySelector(".tags").innerText = tags.join(', ')
78+
result_div.querySelector(".tags").innerText = tags.join(", ")
8579
result_div.querySelector(".snippet").innerText = text.substring(0, excerpt_length) + "..."
86-
87-
88-
const text_match_positions = Object.values(result?.matchData?.metadata ?? {}).flatMap(z => z?.text?.position ?? []).sort(([a,_a], [b,_b]) => a - b)
89-
const title_match_positions = Object.values(result?.matchData?.metadata ?? {}).flatMap(z => z?.title?.position ?? []).sort(([a,_a], [b,_b]) => a - b)
90-
80+
81+
const text_match_positions = Object.values(result?.matchData?.metadata ?? {})
82+
.flatMap((z) => z?.text?.position ?? [])
83+
.sort(([a, _a], [b, _b]) => a - b)
84+
const title_match_positions = Object.values(result?.matchData?.metadata ?? {})
85+
.flatMap((z) => z?.title?.position ?? [])
86+
.sort(([a, _a], [b, _b]) => a - b)
87+
9188
console.error(title_match_positions)
92-
if(title_match_positions.length > 0) {
89+
if (title_match_positions.length > 0) {
9390
const strong_el = document.createElement("strong")
9491
strong_el.innerText = title
9592
result_div.querySelector(".title").innerHTML = ``
9693
result_div.querySelector(".title").appendChild(strong_el)
9794
}
98-
99-
if(text_match_positions.length > 0) {
100-
101-
102-
103-
95+
96+
if (text_match_positions.length > 0) {
10497
// console.log(text_match_positions)
10598
// console.log(find_longest_run(text_match_positions, 50))
10699
// console.log(find_longest_run(text_match_positions, 100))
107100
// console.log(find_longest_run(text_match_positions, 200))
108101
// console.log(find_longest_run(text_match_positions, 300))
109102
// console.log(find_longest_run(text_match_positions, 400))
110-
103+
111104
const [start_index, num_matches] = find_longest_run(text_match_positions, excerpt_length)
112-
105+
113106
const excerpt_start = text_match_positions[start_index][0]
114107
const excerpt_end = excerpt_start + excerpt_length
115-
116-
108+
117109
const highlighted_ranges = text_match_positions.slice(start_index, start_index + num_matches)
118-
110+
119111
const elements = highlighted_ranges.flatMap(([h_start, h_length], i) => {
120112
const h_end = h_start + h_length
121113
const word = text.slice(h_start, h_end)
122114
const filler = text.slice(h_end, highlighted_ranges[i + 1]?.[0] ?? excerpt_end)
123-
const word_el = document.createElement('strong')
115+
const word_el = document.createElement("strong")
124116
word_el.innerText = word
125117
return [word_el, filler]
126118
})
127-
128-
const snippet_p = result_div.querySelector(".snippet");
129-
snippet_p.innerHTML = ``;
130-
["...", text.slice(excerpt_start - excerpt_padding, excerpt_start).trimStart(), ...elements, "..."].forEach(el => snippet_p.append(el))
119+
120+
const snippet_p = result_div.querySelector(".snippet")
121+
snippet_p.innerHTML = ``
122+
;["...", text.slice(excerpt_start - excerpt_padding, excerpt_start).trimStart(), ...elements, "..."].forEach((el) => snippet_p.append(el))
131123
}
132-
133-
134-
124+
135125
// text_match_positions.slice(start_index, start_index + num_matches).forEach(([start, length]) => {
136-
137-
138-
126+
139127
search_results.appendChild(result_div)
140-
141128
})
142129
} else {
143130
search_results.innerText = `No results found for "${query}"`
144-
}
131+
}
145132
}
146133
}
147134

148-
149135
const count = (arr, fn) => arr.reduce((a, b) => fn(a) + fn(b), 0)
150136

151-
152-
153137
const find_longest_run = (/** @type{Array<[number, number]>} */ positions, max_dist) => {
154-
const legal_run_size = start_index => positions.slice(start_index).filter(([start, length]) => (start + length) < positions[start_index][0] + max_dist).length
155-
138+
const legal_run_size = (start_index) =>
139+
positions.slice(start_index).filter(([start, length]) => start + length < positions[start_index][0] + max_dist).length
140+
156141
console.warn(range(positions.length).map(legal_run_size))
157-
142+
158143
const best_start = maxby(range(positions.length), legal_run_size)
159144
const best_length = legal_run_size(best_start)
160145
return [best_start, best_length]
161146
}
162-
163147

164148
window.init_search = init_search
165-

src/assets/scripts/sidebar.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@ const sidebar = document.querySelector("#pages-sidebar")
22
const layout = document.querySelector("#pages-layout")
33
const navtoggle = document.querySelector("#toggle-nav")
44

5-
document.querySelector("#toggle-nav").addEventListener("click", function(e) {
5+
document.querySelector("#toggle-nav").addEventListener("click", function (e) {
66
console.log(e)
7-
layout.classList.toggle("pages_show_sidebar");
7+
layout.classList.toggle("pages_show_sidebar")
88
e.stopPropagation()
99
})
1010

11-
window.addEventListener("click", function(e) {
12-
if(
13-
!sidebar.contains(e.target) &&
14-
!navtoggle.contains(e.target)
15-
) {
16-
layout.classList.remove("pages_show_sidebar");
11+
window.addEventListener("click", function (e) {
12+
if (!sidebar.contains(e.target) && !navtoggle.contains(e.target)) {
13+
layout.classList.remove("pages_show_sidebar")
1714
}
1815
})
1916

2017
console.info("zzzz")
21-
console.info(layout)
18+
console.info(layout)

src/assets/styles/homepage.css

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
21
@import url("newdefault.css");
32

43
body {
5-
6-
7-
8-
9-
10-
114
background: url("../homepage/bg.svg");
125
background-color: hsl(231deg 14% 57%);
136
background-size: cover;
14-
157
}
168
main h1 {
179
font-family: "Vollkorn", serif;
@@ -169,7 +161,7 @@ blockquote.banner {
169161
margin-top: -46px;
170162
font-style: unset;
171163
font-size: 1rem;
172-
border-radius: .5em;
164+
border-radius: 0.5em;
173165
box-shadow: 0px 3px 17px #0000001a;
174166
}
175167

@@ -304,7 +296,7 @@ section > div.preview > img {
304296
width: 1em;
305297
}
306298

307-
308-
.homepage, .banner {
299+
.homepage,
300+
.banner {
309301
color: #3c3c3c;
310-
}
302+
}

0 commit comments

Comments
 (0)