瀏覽代碼

:wrench: Make the current navbar item active

Depends on the current page.
DricomDragon 1 年之前
父節點
當前提交
dbc128c9a5
共有 2 個文件被更改,包括 10 次插入7 次删除
  1. 6 3
      makefile
  2. 4 4
      src/templates/navbar.html

+ 6 - 3
makefile

@@ -25,23 +25,26 @@ DIST_FILES := $(DIST_GEN_FILES) $(DIST_INC_FILES) $(DIST_DWN_FILES) $(DIST_EMB_F
 PANDOC_GEN := pandoc --template src/templates/main.html --metadata-file src/meta.yml --wrap=none
 LIST_GEN := yq eval-all '{"data": ., "target": {"content": filename | sub("meta.yml", "html") | sub(".*/", ""), "dir": filename | sub("$(DIR_OF_PROJECTS)/", "") | sub("/[^/]*.yml", "")}} as $$item ireduce ([]; . + $$item) | {"list": .}'
 
+# Functions
+extract_category = $(word 2, $(subst /, ,$(1)))
+
 # Build
 .PHONY: build
 build: $(GEN_CONTENT_FILES)
 	$(info HTML generated)
 
 %.gen.html: %.src.html %.meta.yml $(SRC_TEMPLATES)
-	$(PANDOC_GEN) --metadata-file $*.meta.yml --output $@ $<
+	$(PANDOC_GEN) --metadata-file $*.meta.yml --metadata=category-$(call extract_category,$*) --output $@ $<
 
 %.gen.html: %.src.md %.meta.yml $(SRC_TEMPLATES)
-	$(PANDOC_GEN) --metadata-file $*.meta.yml --output $@ $<
+	$(PANDOC_GEN) --metadata-file $*.meta.yml --metadata=category-$(call extract_category,$*) --output $@ $<
 
 # Build lists
 $(GEN_LIST_YML): $(SRC_LIST_YML)
 	$(LIST_GEN) $(SRC_LIST_YML) > $@
 
 $(DIR_OF_PROJECTS)/content.gen.html: $(DIR_OF_PROJECTS)/content.src.html $(DIR_OF_PROJECTS)/content.meta.yml $(GEN_LIST_YML) $(SRC_TEMPLATES)
-	$(PANDOC_GEN) --metadata-file $(DIR_OF_PROJECTS)/content.meta.yml --metadata-file $(GEN_LIST_YML) --output $@ $<
+	$(PANDOC_GEN) --metadata-file $(DIR_OF_PROJECTS)/content.meta.yml --metadata-file $(GEN_LIST_YML) --metadata=category-projets --output $@ $<
 
 # Distribution
 .PHONY: dist

+ 4 - 4
src/templates/navbar.html

@@ -6,19 +6,19 @@
          alt="V">
     <div class="collapse navbar-collapse" id="joviaNav">
         <ul class="navbar-nav mr-auto">
-            <li class="nav-item">
+            <li class="nav-item $if(category-index)$ active$endif$">
                 <a class="nav-link" href="/index.html">
                     <img src="/include/icon/icons8-48-city.png" alt="|">
                     Accueil
                 </a>
             </li>
-            <li class="nav-item">
+            <li class="nav-item $if(category-cv)$ active$endif$">
                 <a class="nav-link" href="/cv/content.html">
                     <img src="/include/icon/icons8-48-parse-from-clipboard.png" alt="|">
                     CV
                 </a>
             </li>
-            <li class="nav-item dropdown active">
+            <li class="nav-item dropdown$if(category-projets)$ active$endif$">
                 <a class="nav-link dropdown-toggle" href="/projets/content.html" id="dropdown01" data-toggle="dropdown"
                    aria-haspopup="true" aria-expanded="false">
                     <img src="/include/icon/icons8-48-code.png" alt="|">
@@ -47,7 +47,7 @@
                     </a>
                 </div>
             </li>
-            <li class="nav-item">
+            <li class="nav-item$if(category-contact)$ active$endif$">
                 <a class="nav-link" href="/contact/content.html">
                     <img src="/include/icon/icons8-48-secured-letter.png" alt="|">
                     Contact