ussg

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit d0b430a78f98b4a7192bc6395e715af57d2c21ac
parent 5d1d01b86b36f249b5f98daee4353b694a226d09
Author: Ellenor Bjornsdottir <ellenor@umbrellix.net>
Date:   Mon, 12 Sep 2022 12:13:33 +0000

Simple incomplete navbar

Diffstat:
Mdoc/examples/headers | 3+++
Adoc/examples/navbar | 2++
Aplugins/navbar.tm | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mussg-page | 27++++++++++++++++++++++++++-
4 files changed, 88 insertions(+), 1 deletion(-)

diff --git a/doc/examples/headers b/doc/examples/headers @@ -3,3 +3,6 @@ X-Site-Title: UmbrellixSSG Test Site X-Synoptic-Title: UmbrellixSSG Test Site Verbatim: doc/examples/topnav.htfrag Verbatim: doc/examples/bottomnav.htfrag +Plugin: plugins/navbar.tm +Navbar-Prefix: html/ +Navbar-Source: doc/examples/navbar diff --git a/doc/examples/navbar b/doc/examples/navbar @@ -0,0 +1,2 @@ +/index.html Index +/contact.html Contact me diff --git a/plugins/navbar.tm b/plugins/navbar.tm @@ -0,0 +1,57 @@ +# This is an UmbrellixSSG Plugin. +# It is sourced into ::templcmds::. +# It can use any header, although it cannot limit them +# to being single-use as headers have already been parsed. +# If that's needed, one will need to just pick off the last +# option. +# Some checking can be done. + +proc navbar {} { + # So, the user wants a side navbar, huh? + # We'll have to look in the Navbar-Source header. + set prefix "" + if {![catch {dict get $::headers navbar-prefix} navprefix]} {set prefix [file normalize $navprefix]} + # This is the prefix that is assumed to be on $::outputfile during generation. This is used to calculate "this page." + + if {[catch {dict get $::headers navbar-title} navtitle]} {set navtitle ""} + #mimicking the werc function of the same nature + + if {[catch {set ::outputfile} outputfile]} { + puts stderr "Warn: Navbar plugin: You are running ussg in stdout mode. Navbar doesn't work in stdout mode; it needs the output file name to know if it's on \"this page\". Navbar will still do its best, but there will be no differentiation of this page from not this page." + set outputfile "" + } ;# without an input filename we cannot work properly. + + if {[catch {dict get $::headers navbar-source} navsource]} { + puts stderr "Warn: Navbar plugin: there is no Navbar-Source document header. This is required to use Navbar, and must be a regular file of tab-separated values: path, label." + } { + # off to the races, folks! + if {[catch {open [file normalize [lindex $navsource end]] r} provinputfd]} { + puts stderr [format "Warn: Navbar plugin: fixed-paths file \'%s\' could not be opened for reading. This file must be openable for Navbar to work. \[open\] reports:" $navsource] + puts stderr $provinputfd + return + } { + if {$navtitle != ""} {puts $::outputfd [format "<p class=\"sideBarTitle\">%s</p>" $navtitle]} + puts $::outputfd "<ul>" + while {![eof $provinputfd]} { + set garbage [lassign [split [gets $provinputfd] "\t"] path label] + if {$path == ""} {continue} + if {$outputfile == ""} { + puts $::outputfd [format "<li><a href=\"%s\">&raquo; <i>%s</i></a></li>" $path $label] + } { + set isthispath 0 + if {[string index $path 0] == "/"} { + # then we can see if it's this path + if {[file normalize [format "%s/%s" $prefix $path]] == [file normalize $outputfile]} {set isthispath 1} + } + if {$isthispath} { + puts $::outputfd [format "<li><a href=\"%s\" class=\"thisPage\">&rsaquo; <i>%s</i></a></li>" $path $label] + } { + puts $::outputfd [format "<li><a href=\"%s\">&raquo; <i>%s</i></a></li>" $path $label] + } + } + puts stderr [format "info: navbar plugin: prefix: %s outputfile: %s path: %s label: %s isthispath: %s" $prefix $outputfile $path $label $isthispath] + } + puts $::outputfd "</ul>" + } + } +} diff --git a/ussg-page b/ussg-page @@ -224,6 +224,8 @@ set headermulti { favicon 0 style 1 verbatim 1 + execverbatim 1 + plugin 1 } set parsedargs [opts [list h v H: M: help version headers: markdown:] $argv] @@ -331,6 +333,9 @@ proc parseheader {lin} { dict set ::headers $word $content # We will just allow overriding. } + } { + # Assume 1 + dict lappend ::headers $word $content } } @@ -376,7 +381,7 @@ if {[catch {dict get $::headers template} templatehdr]} { exit 78 } { if {[catch {open [file normalize $templatehdr] r} provinputfd]} { - puts stderr [format "Error: template file \'%s\' could not be opened for reading. Balking now; this is fatal. \[open\] reports:" $::templatehdr] + puts stderr [format "Error: template file \'%s\' could not be opened for reading. Balking now; this is fatal. \[open\] reports:" $templatehdr] puts stderr $provinputfd exit 66 } { @@ -384,6 +389,26 @@ if {[catch {dict get $::headers template} templatehdr]} { } } +proc templcmdsrc {script} { + if {[catch {open [file normalize $script] r} provinputfd]} { + puts stderr [format "Error: template command plugin file \'%s\' could not be opened for reading. Balking now; this is fatal. \[open\] reports:" $script] + puts stderr $provinputfd + exit 66 + } { + set fp $provinputfd + } + #set fp [open $script r] + set ev [list namespace eval ::templcmds [read $fp]] + close $fp + uplevel "#0" $ev +} + +if {![catch {dict get $::headers plugin} pluginhdr]} { + foreach {script} $pluginhdr { + templcmdsrc $script + } +} + namespace eval ::templcmds { proc title {} { # output page title