Skip to content

Commit

Permalink
Merge pull request #213 from 1712n/nav-rework
Browse files Browse the repository at this point in the history
Navigation: Rework navigation menu
  • Loading branch information
marina-chibizova authored Aug 22, 2023
2 parents 0d26772 + eb6e906 commit 6dada2f
Show file tree
Hide file tree
Showing 36 changed files with 106 additions and 101 deletions.
12 changes: 9 additions & 3 deletions README-DEV.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# Content Organization
# Developement Documentation

## Sections
## Content Organization

### Sections

`attacks`, `mvt` and `oracles` are the main content sections.

## Mappings
### Mappings

`attack-types`, `entity-types` and `target-entities` don't hold content and provide data for the respective taxonomies mapped under `attacks/posts`. Similarly `entities` is a taxonomy mappped under `market-health`.

## Navigation

Use page params `navShowPages`, `navShowTaxonomies` and `navShowTerms` to configure how sections should appear on the navigation menu. Set `true` to show and `false` to hide.

## See also

Refer to Hugo [documentation](https://gohugo.io/content-management/organization/) for more help
10 changes: 5 additions & 5 deletions assets/_custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
color: hsl(0, 0%, 45%);
}

.term {
}
// .term {
// }
}
}
}
Expand All @@ -40,7 +40,7 @@
padding: 0 0 0 .5rem;
}

.submenu {
.li-h2 {
h2 {
font-size: 1.1em;
font-weight: 600;
Expand All @@ -56,11 +56,11 @@
}
}

.submenu ~ .submenu {
.li-h2 ~ .li-h2 {
margin-top: 1.5em;
}

.subsection {
.li-h3 {
li {
margin: 0;
}
Expand Down
4 changes: 2 additions & 2 deletions config/_default/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ permalinks:
attack-types: "/attacks/posts/attack-types/:title"

# market-health
entities: "/market-health/posts/entities/:title"
entities: "/market-health/entities/:title"

cascade:
- _target:
path: "**/posts/**"
type: posts

- _target:
path: "/market-health/posts/**"
path: "/market-health/**"
type: posts

- _target:
Expand Down
1 change: 1 addition & 0 deletions content/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
type: docs
title: Distributed Networks Institute (DNI)
bookFlatSection: true
navShowPages: true
---

## DNI Mission
Expand Down
1 change: 1 addition & 0 deletions content/attacks/_index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
title: Crypto Attacks
hide: true
navShowPages: true
---
1 change: 1 addition & 0 deletions content/attacks/docs/_index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
title: "Wiki"
hide: true
navShowPages: true
---
2 changes: 2 additions & 0 deletions content/attacks/posts/_index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---
title: "Incidents"
navShowTaxonomies: true
navShowPages: false
---
2 changes: 1 addition & 1 deletion content/entities/_index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Entities
type: taxonomy
url: market-health/posts/entities
url: market-health/entities
---
2 changes: 1 addition & 1 deletion content/market-health/_index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Market Health
hide: true
navShowTaxonomies: false
---

## Market Health: Anomalies & Integrity Studies
Expand Down
8 changes: 0 additions & 8 deletions content/market-health/posts/_index.md

This file was deleted.

2 changes: 1 addition & 1 deletion layouts/partials/docs/menu-anchor.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
>{{ .item.LinkTitle }}</a>
{{ end }}

{{ if .control }}
{{ if .showControls }}
<button class="collapsible-control"></button>
{{ end }}
162 changes: 82 additions & 80 deletions layouts/partials/docs/menu.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,78 @@
{{ define "taxonomies" }}
{{ $page := .page }}
{{ $section := .item }}
{{ $path := .path }}
{{ $level := add .level 1 }}

{{ range $taxonomy, $terms := site.Taxonomies }}
{{ with site.GetPage $taxonomy }}
{{ if (hasPrefix .RelPermalink $section.RelPermalink) }}
{{ $showTerms := .Params.navShowTerms | default false }}

<li class="taxonomy {{ if $showTerms }}collapsible{{ end }}">
<h{{ $level }}>{{ partial "docs/menu-anchor" (dict "page" $page "item" . "showControls" $showTerms) }}</h{{ $level }}>

{{ if $showTerms }}
{{ with $terms }}
{{ $name := .LinkTitle | urlize | lower }}
{{ $path = printf "%s-%s" $path $name }}
{{ $id := printf "ul%d-%s" $level $path }}

<ul class="terms collapsible-target" id="{{ $id }}">
{{ range . }}
<li>{{ partial "docs/menu-anchor" (dict "page" $page "item" .Page) }}</li>
{{ end }}
</ul>
{{ end }}
{{ end }}
</li>
{{ end }}
{{ end }}
{{ end }}
{{ end }}

{{ define "menu" }}
{{ $page := .page }}
{{ $path := .path }}
{{ $level := add .level 1 }}

{{ $name := "" }}
{{ $id := "" }}
{{ $expand := "" }}

{{ $name = .LinkTitle | urlize | lower }}

{{ if $path }}
{{ $path = printf "%s-%s" $path $name }}
{{ else }}
{{ $path = $name }}
{{ end }}

{{ $id = printf "ul%d-%s" $level $path }}

{{ $showPages := (and (.item.Param "navShowPages") (gt (.item.Pages | len) 0)) | default false }}
{{ $showTaxonomies := .item.Param "navShowTaxonomies" | default false }}
{{ $expand = (or $showPages $showTaxonomies) | default false }}

<li class="li-h{{ $level }} {{ if $expand }}collapsible{{ end }}">
<h{{ $level }}>{{ partial "docs/menu-anchor" (dict "page" $page "item" .item "showControls" $expand) }}</h{{ $level }}>

{{ if $showTaxonomies }}
<ul class="taxonomies collapsible-target" id="{{ $id }}">
{{ template "taxonomies" (dict "page" $page "item" .item "level" $level "path" $path) }}
</ul>
{{ end }}

{{ if $showPages }}
<ul class="pages collapsible-target" id="{{ $id }}">
{{ range .item.Pages }}
{{ template "menu" (dict "page" $page "item" . "level" $level "path" $path) }}
{{ end }}
</ul>
{{ end }}
</li>
{{ end }}

<nav>
{{ partial "docs/brand" . }}
{{ partial "docs/search" . }}
Expand All @@ -6,90 +81,17 @@
{{ end }}

{{ partial "docs/inject/menu-before" . }}

{{ $page := .Page }}
{{ $expandTerms := site.Params.expandTerms | default false }}

<div class="book-tree">
<!-- initialize sections ids -->
{{ $ul2 := "" }}
{{ $ul3 := "" }}
{{ $ul4 := "" }}

<!-- list main sections -->

<ul class="book-tree">
{{ range site.Home.Pages }}
<!-- show collapsibles only in sections with children -->
{{ if (gt (.Pages | len) 0) }}
<div class="submenu collapsible">
{{ $ul2 = .LinkTitle | urlize | lower }}
<h2>{{ partial "docs/menu-anchor" (dict "page" $page "item" . "control" true) }}</h2>
<ul class="collapsible-target" id="ul2-{{ $ul2 }}">
<!-- list sub sections -->
{{ range .Pages }}
{{ if eq .Kind "section" }}
<li class="subsection collapsible">
<!-- special case: posts -->
{{ if eq .Type "posts" }}
{{ $subsection := . }}
{{ $ul3 = .LinkTitle | urlize | lower }}
<h3>{{ partial "docs/menu-anchor" (dict "page" $page "item" . "control" true) }}</h3>
<ul class="taxonomies collapsible-target" id="ul3-{{ $ul2 }}-{{ $ul3 }}">
<!-- NOTE: Taxonomies are site-wide and not section-specific. -->
{{ range $taxonomy, $terms := site.Taxonomies }}
{{ with site.GetPage $taxonomy }}
{{ if (hasPrefix .RelPermalink $subsection.RelPermalink) }}
<li class="taxonomy {{ if $expandTerms }}collapsible{{ end }}">
<h4>{{ partial "docs/menu-anchor" (dict "page" $page "item" . "control" $expandTerms) }}</h4>

{{ if $expandTerms }}
{{ with $terms }}
{{ $ul4 = .LinkTitle | urlize | lower }}
<ul class="terms collapsible-target" id="ul4-{{ $ul2 }}-{{ $ul3 }}-{{ $ul4 }}">
{{ range . }}
<li>{{ partial "docs/menu-anchor" (dict "page" $page "item" .Page) }}</li>
{{ end }}
</ul>
{{ end }}
{{ end }}
</li>
{{ end }}
{{ end }}
{{ end }}
</ul>

<!-- other cases -->
{{ else }}
{{ if .Pages }}
{{ $ul3 = .LinkTitle | urlize | lower }}
<h3>{{ partial "docs/menu-anchor" (dict "page" $page "item" . "control" true) }}</h3>
<ul class="pages collapsible-target" id="ul3-{{ $ul2 }}-{{ $ul3 }}">
{{ range .Pages }}
<li>{{ partial "docs/menu-anchor" (dict "page" $page "item" .) }}</li>
{{ end }}
</ul>
{{ else }}
<h3>{{ partial "docs/menu-anchor" (dict "page" $page "item" .) }}</h3>
{{ end }}
{{ end }}
</li>
{{ end }}
{{ end }}
</ul>
</div>
{{ else }}
<div class="submenu">
<h2>{{ partial "docs/menu-anchor" (dict "page" $page "item" .) }}</h2>
</div>
{{ end }}
{{ template "menu" (dict "page" . "item" . "level" 1 "path" "") }}
{{ end }}

<!-- list global taxonomies -->

<div class="submenu external-links">
<li class="li-h2 external-links">
<h2>External</h2>
{{ partial "docs/menu-hugo" .Site.Menus.external }}
</div>
</div>
{{ partial "docs/menu-hugo" site.Menus.external }}
</li>
</ul>

{{ partial "docs/inject/menu-after" . }}
</nav>
Expand Down

0 comments on commit 6dada2f

Please sign in to comment.