Skip to content

Commit 78faa81

Browse files
committed
refactor(html): rework breadcrumbs
1 parent ac1b32f commit 78faa81

19 files changed

+63
-75
lines changed

build_css.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { browserslistToTargets, transform } from "npm:lightningcss";
55
const browsers = browserslist(">= 0.5%, not dead");
66

77
const styles =
8-
await $`deno run -A npm:tailwindcss@3.4.1 --input src/html/templates/styles.css`
8+
await $`deno run -A npm:tailwindcss@3.4.3 --input src/html/templates/styles.css`
99
.text();
1010
const stylesWrapped = ".ddoc {" + styles + "}";
1111
const stylesFinal = transform({
@@ -18,7 +18,7 @@ const stylesFinal = transform({
1818
await Deno.writeFile("src/html/templates/styles.gen.css", stylesFinal.code);
1919

2020
const page =
21-
await $`deno run -A npm:tailwindcss@3.4.1 --input src/html/templates/pages/page.css`
21+
await $`deno run -A npm:tailwindcss@3.4.3 --config=./src/html/templates/pages/tailwind.config.ts --input src/html/templates/pages/page.css`
2222
.bytes();
2323
const pageFinal = transform({
2424
filename: "./page.css",

src/html/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ pub fn setup_hbs<'t>() -> Result<Handlebars<'t>, anyhow::Error> {
339339
include_str!("./templates/pages/index.hbs"),
340340
)?;
341341
reg.register_template_string(
342-
"pages/search_bar",
343-
include_str!("./templates/pages/search_bar.hbs"),
342+
"pages/top_nav",
343+
include_str!("./templates/pages/top_nav.hbs"),
344344
)?;
345345
reg.register_template_string(
346346
"pages/search_results",
@@ -352,6 +352,10 @@ pub fn setup_hbs<'t>() -> Result<Handlebars<'t>, anyhow::Error> {
352352
)?;
353353

354354
// icons
355+
reg.register_template_string(
356+
"icons/arrow",
357+
include_str!("./templates/icons/arrow.svg"),
358+
)?;
355359
reg.register_template_string(
356360
"icons/copy",
357361
include_str!("./templates/icons/copy.svg"),

src/html/render_context.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,76 +145,72 @@ impl<'ctx> RenderContext<'ctx> {
145145
}
146146

147147
pub fn get_breadcrumbs(&self) -> BreadcrumbsCtx {
148+
let index_name =
149+
self.ctx.package_name.clone().unwrap_or("index".to_string());
150+
148151
let parts = match self.current_resolve {
149152
UrlResolveKind::Root => vec![BreadcrumbCtx {
150-
name: "index".to_string(),
153+
name: index_name,
151154
href: "".to_string(),
152155
is_symbol: false,
153156
is_first_symbol: false,
154-
is_all_symbols_part: false,
155157
}],
156158
UrlResolveKind::AllSymbols => {
157159
vec![
158160
BreadcrumbCtx {
159-
name: "index".to_string(),
161+
name: index_name,
160162
href: self
161163
.ctx
162164
.href_resolver
163165
.resolve_path(self.current_resolve, UrlResolveKind::Root),
164166
is_symbol: false,
165167
is_first_symbol: false,
166-
is_all_symbols_part: false,
167168
},
168169
BreadcrumbCtx {
169170
name: "all symbols".to_string(),
170171
href: "".to_string(),
171172
is_symbol: false,
172173
is_first_symbol: false,
173-
is_all_symbols_part: true,
174174
},
175175
]
176176
}
177177
UrlResolveKind::File(file) => {
178178
if self.current_specifier == self.ctx.main_entrypoint.as_ref() {
179179
vec![BreadcrumbCtx {
180-
name: "index".to_string(),
180+
name: index_name,
181181
href: "".to_string(),
182182
is_symbol: false,
183183
is_first_symbol: false,
184-
is_all_symbols_part: false,
185184
}]
186185
} else {
187186
vec![
188187
BreadcrumbCtx {
189-
name: "index".to_string(),
188+
name: index_name,
190189
href: self
191190
.ctx
192191
.href_resolver
193192
.resolve_path(self.current_resolve, UrlResolveKind::Root),
194193
is_symbol: false,
195194
is_first_symbol: false,
196-
is_all_symbols_part: false,
197195
},
198196
BreadcrumbCtx {
199197
name: file.to_name(),
200198
href: "".to_string(),
201199
is_symbol: false,
202200
is_first_symbol: false,
203-
is_all_symbols_part: false,
204201
},
205202
]
206203
}
207204
}
208205
UrlResolveKind::Symbol { file, symbol } => {
209206
let mut parts = vec![BreadcrumbCtx {
210-
name: "index".to_string(),
207+
name: index_name,
211208
href: self
212209
.ctx
213210
.href_resolver
214211
.resolve_path(self.current_resolve, UrlResolveKind::Root),
215212
is_symbol: false,
216213
is_first_symbol: false,
217-
is_all_symbols_part: false,
218214
}];
219215

220216
if self.current_specifier != self.ctx.main_entrypoint.as_ref() {
@@ -226,7 +222,6 @@ impl<'ctx> RenderContext<'ctx> {
226222
.resolve_path(self.current_resolve, UrlResolveKind::File(file)),
227223
is_symbol: false,
228224
is_first_symbol: false,
229-
is_all_symbols_part: false,
230225
});
231226
}
232227

@@ -245,7 +240,6 @@ impl<'ctx> RenderContext<'ctx> {
245240
),
246241
is_symbol: true,
247242
is_first_symbol: i == 0,
248-
is_all_symbols_part: false,
249243
};
250244
breadcrumbs.push(breadcrumb);
251245

src/html/sidepanels.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ struct SidepanelPartitionCtx {
4545

4646
#[derive(Debug, Serialize, Clone)]
4747
pub struct SidepanelCtx {
48-
package_name: Option<String>,
4948
partitions: Vec<SidepanelPartitionCtx>,
5049
}
5150

@@ -90,10 +89,7 @@ impl SidepanelCtx {
9089
})
9190
.collect();
9291

93-
Self {
94-
package_name: ctx.package_name.clone(),
95-
partitions,
96-
}
92+
Self { partitions }
9793
}
9894
}
9995

@@ -106,7 +102,6 @@ struct IndexSidepanelFileCtx {
106102

107103
#[derive(Debug, Serialize, Clone)]
108104
pub struct IndexSidepanelCtx {
109-
package_name: Option<String>,
110105
root_url: String,
111106
all_symbols_url: Option<String>,
112107
kind_partitions: Vec<SidepanelPartitionCtx>,
@@ -182,7 +177,6 @@ impl IndexSidepanelCtx {
182177
.collect::<Vec<_>>();
183178

184179
Self {
185-
package_name: ctx.package_name.clone(),
186180
root_url: ctx.href_resolver.resolve_path(
187181
current_file.map_or(UrlResolveKind::Root, UrlResolveKind::File),
188182
UrlResolveKind::Root,

src/html/templates/breadcrumbs.hbs

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,27 @@
1-
<div class="mb-6 whitespace-nowrap leading-none">
1+
<div class="whitespace-nowrap inline-flex gap-1.5 items-center">
22
{{~#each parts~}}
33
{{~#if this.is_first_symbol~}}
4-
<span class="inline-flex">
4+
<span>
55
{{~/if~}}
66

7-
{{~#unless @last~}}
8-
<a class="link {{#if @first}}italic{{/if}}" href="{{this.href}}">
9-
{{~this.name~}}
10-
</a>
11-
12-
{{~#if this.is_symbol~}}
13-
<span>.</span>
14-
{{~else~}}
15-
<span class="px-1.5 text-xs text-stone-600">&#x25B6;</span>
16-
{{~/if~}}
17-
{{~/unless~}}
18-
197
{{~#if @last~}}
20-
<span class="{{#if @first~}}
21-
italic
22-
{{~else~}}
23-
{{~#if this.is_all_symbols_part}}
24-
italic
25-
{{~/if~}}
26-
{{~/if}}">
27-
{{~this.name~}}
28-
</span>
8+
<span class="{{#if @first}}text-xl lg:text-2xl leading-none font-bold{{else}}lg:text-xl leading-[0.9em]{{/if}}">
9+
{{~this.name~}}
10+
</span>
11+
{{~else~}}
12+
<a class="link {{#if @first}}text-xl lg:text-2xl leading-none font-bold{{else}}lg:text-xl leading-[0.9em]{{/if}}" href="{{this.href}}">
13+
{{~this.name~}}
14+
</a>
15+
16+
{{~#if this.is_symbol~}}
17+
<span>.</span>
18+
{{~else~}}
19+
<span class="text-stone-600">{{~> icons/arrow ~}}</span>
20+
{{~/if~}}
2921
{{~/if~}}
3022

31-
{{~#if @last~}}
32-
{{~#if this.is_symbol~}}
33-
</span>
34-
{{~/if~}}
23+
{{~#if (and @last this.is_symbol)~}}
24+
</span>
3525
{{~/if~}}
3626
{{~/each~}}
3727
</div>

src/html/templates/icons/arrow.svg

Lines changed: 8 additions & 0 deletions
Loading

src/html/templates/index_sidepanel.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<nav id="sidepanel">
2-
{{~> sidepanel_common package_name=package_name ~}}
2+
{{~> sidepanel_common ~}}
33

44
<div class="max-lg:hidden peer-checked:block">
55
{{~#if all_symbols_url~}}

src/html/templates/pages/all_symbols.hbs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{{~> pages/html_head html_head_ctx ~}}
22

33
<div id="content">
4-
{{~> breadcrumbs breadcrumbs_ctx ~}}
5-
{{~> pages/search_bar ~}}
4+
{{~> pages/top_nav ~}}
65

7-
<main>
6+
<main>
87
{{~> symbol_content content ~}}
98
</main>
109

src/html/templates/pages/index.hbs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
{{~> index_sidepanel sidepanel_ctx ~}}
44

55
<div id="content">
6-
{{~> breadcrumbs breadcrumbs_ctx ~}}
7-
{{~> pages/search_bar ~}}
6+
{{~> pages/top_nav ~}}
87

98
<main>
109
{{~#if module_doc ~}}
@@ -13,6 +12,6 @@
1312
</main>
1413

1514
{{~> pages/search_results ~}}
16-
<div>
15+
</div>
1716
</body>
1817
</html>

0 commit comments

Comments
 (0)