Skip to content

Commit d2fa36b

Browse files
committed
fix(partial): partial fix for tocs in imports
Signed-off-by: Laura Santamaria <[email protected]>
1 parent 2a40d22 commit d2fa36b

File tree

7 files changed

+73
-13
lines changed

7 files changed

+73
-13
lines changed

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
This site is built using [Zola](https://www.getzola.org/), a static site generator build with Rust. The theme is [Juice](https://www.getzola.org/themes/juice/).
44
- Zola [Installation instructions](https://www.getzola.org/documentation/getting-started/installation/)
5-
- Juice
5+
- Juice [Installation info](https://juice.huhu.io/#installation) - Note that I've explicitly dropped the git history and VCS info from the theme directory.
66

7-
Under the hood, Zola uses [Tera](https://keats.github.io/tera/) for templating.
7+
Under the hood, Zola uses [Tera](https://keats.github.io/tera/) for templating.
8+
9+
## Structure
10+
11+
The site lives in the `site` directory. Content like pages or blog posts live in, appropriately, `content`. Any kind of image like screenshots would live in `static`.
12+
13+
The `templates` directory extends elements from the theme, which is stored in, appropriately, `themes/juice`.
14+
15+
## Building
16+
17+
Once you've installed Zola, proceed as follows:
18+
19+
```bash
20+
cd site
21+
zola serve
22+
```
23+
24+
Go to the URL for the webserver (likely `localhost:1111`) to explore the site.
25+
26+
You can also use `zola build` to build it once to the `public` directory if you so choose.

site/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ highlight_theme = "inspired-github"
4343
render_emoji = true
4444
external_links_target_blank = true
4545
external_links_no_referrer = true
46+
insert_anchor_links = "left"
4647

4748
[extra]
4849
# Put all your custom variables here

site/content/about/_index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
title = "Project information"
33
description = "About the project"
44
weight = 1
5-
+++
5+
+++
6+
7+
Use these pages to learn more about the project, our governance, and adopters.

site/content/about/governance.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ toc = true
77
[extra]
88
fileimport = "GOVERNANCE"
99
+++
10-

site/templates/_macros.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,3 @@
2121
{% endif %}
2222
</nav>
2323
{% endmacro render_header %}
24-
25-
{% macro github_md_embed(filename) %}
26-
{% set response = load_data(url="https://raw.githubusercontent.com/bootc-dev/bootc/refs/heads/main/" ~ filename ~ ".md") %}
27-
{{ response }}
28-
{% endmacro github_md_embed %}

site/templates/_variables.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@
3333
/* Font used for text */
3434
--text-font-family: "Red Hat Text", sans-serif;
3535
}
36+
.zola-anchor {
37+
margin-left: -2rem;
38+
margin-right: .75rem;
39+
}
3640
</style>

site/templates/imported.html

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,52 @@
77
</header>
88
{% endblock header %}
99

10+
{% block sidebar %}
11+
<div class="sidebar">
12+
</div>
13+
{% endblock sidebar %}
14+
1015
{% block content %}
16+
{% set response = load_data(url="https://raw.githubusercontent.com/bootc-dev/bootc/refs/heads/main/" ~ page.extra.fileimport ~ ".md") %}
1117
<div class="heading-text">{{ page.description }}</div>
12-
{{ macros::github_md_embed(filename=page.extra.fileimport) | markdown | safe }}
18+
{{ response | markdown | safe }}
1319
{% endblock content %}
1420

15-
{% block sidebar %}
16-
<div class="sidebar">
21+
{% block toc %}
22+
{% set response = load_data(url="https://raw.githubusercontent.com/bootc-dev/bootc/refs/heads/main/" ~ page.extra.fileimport ~ ".md") %}
23+
{% set toc = response | markdown | linebreaksbr | split(pat="<br>") %}
24+
{% set mapset = [] %}
25+
{%- for elem in toc %}
26+
{%- if elem is starting_with("<h") %}
27+
{%- set mapset1 = elem | regex_replace(pattern=`<h(?P<level>\d) id="(?P<anchor>.*)">(?P<heading>.*)</h\d>`, rep=`$level,$anchor,$heading`) %}
28+
{% set_global mapset = mapset | concat(with=mapset1) %}
29+
{%- endif %}
30+
{%- endfor %}
31+
<p>{{ mapset | json_encode(pretty=true) | safe }}</p>
32+
<div class="toc">
33+
<div class="toc-sticky">
34+
<ul>
35+
{%- for elem in toc %}
36+
{%- if elem is starting_with("<h1") %}
37+
{%- set id_val = elem | regex_replace(pattern=`<h1 id="(?P<anchor>.*)">.*</h1>`, rep=`$anchor`) %}
38+
<li class="toc-item"><a href="#{{ id_val }}" class="subtext">{{ elem | regex_replace(pattern=`<h1 id=".*">(?P<heading>.*)</h1>`, rep=`$heading`) | as_str }}</a></li>
39+
{%- else %}
40+
<ul>
41+
{%- if elem is starting_with("<h2") %}
42+
{%- set id_val = elem | regex_replace(pattern=`<h2 id="(?P<anchor>.*)">.*</h2>`, rep=`$anchor`) %}
43+
<li class="toc-item"><a href="#{{ id_val }}" class="subtext">{{ elem | regex_replace(pattern=`<h2 id=".*">(?P<heading>.*)</h2>`, rep=`$heading`) | as_str }}</a></li>
44+
{%- else %}
45+
<ul>
46+
{%- if elem is starting_with("<h3") %}
47+
{%- set id_val = elem | regex_replace(pattern=`<h3 id="(?P<anchor>.*)">.*</h3>`, rep=`$anchor`) %}
48+
<li class="toc-item"><a href="#{{ id_val }}" class="subtext">{{ elem | regex_replace(pattern=`<h3 id=".*">(?P<heading>.*)</h3>`, rep=`$heading`) | as_str }}</a></li>
49+
{%- endif %}
50+
</ul>
51+
{%- endif %}
52+
</ul>
53+
{%- endif %}
54+
{%- endfor %}
55+
</ul>
56+
</div>
1757
</div>
18-
{% endblock sidebar %}
58+
{% endblock toc %}

0 commit comments

Comments
 (0)