add default script for burger menu on retarded devices

This commit is contained in:
gutmet 2023-03-05 14:04:02 +01:00
parent dac343fa51
commit 59a11a0882
7 changed files with 86 additions and 199 deletions

View File

@ -22,6 +22,7 @@ const postsPerPage int = 5
var blogname string var blogname string
var folder string var folder string
var style string var style string
var script string
var t *template.Template var t *template.Template
var rssTemplate *template.Template var rssTemplate *template.Template
var categories map[string][]Post var categories map[string][]Post
@ -66,6 +67,7 @@ func emitPostPage(post Post) string {
page.Blogdir = folder page.Blogdir = folder
page.Title = post.Meta.Title page.Title = post.Meta.Title
page.Style = style page.Style = style
page.Script = script
page.Content = post.Content page.Content = post.Content
page.Time = post.Meta.Date.Format(TimeFormat) page.Time = post.Meta.Date.Format(TimeFormat)
page.Blogpost = true page.Blogpost = true
@ -110,6 +112,7 @@ func emitIndexPage(i int, posts []Post, total int) {
page := Page{} page := Page{}
page.Title = blogname page.Title = blogname
page.Style = style page.Style = style
page.Script = script
page.Blogdir = folder page.Blogdir = folder
page.Blogname = blogname page.Blogname = blogname
page.Blogpost = false page.Blogpost = false
@ -180,6 +183,7 @@ func makeCategories() {
page := Page{} page := Page{}
page.Title = blogname + ": Categories" page.Title = blogname + ": Categories"
page.Style = style page.Style = style
page.Script = script
keySet := keys(categories) keySet := keys(categories)
sort.Strings(keySet) sort.Strings(keySet)
for _, k := range keySet { for _, k := range keySet {
@ -200,6 +204,7 @@ func makeTimeline(posts []Post) {
page := Page{} page := Page{}
page.Title = blogname + ": Timeline" page.Title = blogname + ": Timeline"
page.Style = style page.Style = style
page.Script = script
page.TimelineListing = posts page.TimelineListing = posts
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
t.Execute(buf, page) t.Execute(buf, page)
@ -269,15 +274,18 @@ func Generate(dir string) {
categories = make(map[string][]Post) categories = make(map[string][]Post)
var err error var err error
var err2 error var err2 error
var err3 error
style, err = goutil.ReadFile("style.css") style, err = goutil.ReadFile("style.css")
templateString, err2 := goutil.ReadFile("template") script, err2 = goutil.ReadFile("script.js")
templateString, err3 := goutil.ReadFile("template")
t = template.Must(template.New("page").Parse(templateString)) t = template.Must(template.New("page").Parse(templateString))
rssTemplateString, _ := goutil.ReadFile("rssTemplate") rssTemplateString, _ := goutil.ReadFile("rssTemplate")
rssTemplate = template.Must(template.New("rss").Parse(rssTemplateString)) rssTemplate = template.Must(template.New("rss").Parse(rssTemplateString))
if err == nil && err2 == nil { if err == nil && err2 == nil && err3 == nil {
makeBlog() makeBlog()
} else { } else {
fmt.Println(err) fmt.Println(err)
fmt.Println(err2) fmt.Println(err2)
fmt.Println(err3)
} }
} }

View File

@ -4,48 +4,34 @@ import (
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
"os"
"path/filepath"
finstr "git.gutmet.org/finstr.git/initer" finstr "git.gutmet.org/finstr.git/initer"
goutil "git.gutmet.org/goutil.git/misc" goutil "git.gutmet.org/goutil.git/misc"
"git.gutmet.org/wombat.git/gallery" "git.gutmet.org/wombat.git/gallery"
"os"
"path/filepath"
) )
const ( const (
initflag = ".wombat" initflag = ".wombat"
) )
type Style int var checkpaths []string = []string{initflag, "stage0", "template", "style.css", "script.js"}
const ( func dumpInitFiles() error {
Minimal Style = 0 err := goutil.WriteFile("template", defaultTemplate)
BSStarter Style = 1
)
func templateAndCSS(style Style) (string, string) {
switch style {
case BSStarter:
return bsStarterTemplate, bsStarterStyle
case Minimal:
fallthrough
default:
return defaultTemplate, defaultStyle
}
}
var checkpaths []string = []string{initflag, "stage0", "template", "style.css"}
func dumpInitFiles(style Style) error {
template, css := templateAndCSS(style)
err := goutil.WriteFile("template", template)
if err != nil { if err != nil {
return err return err
} }
err = goutil.WriteFile("rssTemplate", rssTemplate) err = goutil.WriteFile("rssTemplate", defaultRSSTemplate)
if err != nil { if err != nil {
return err return err
} }
err = goutil.WriteFile("style.css", css) err = goutil.WriteFile("style.css", defaultStyle)
if err != nil {
return err
}
err = goutil.WriteFile("script.js", defaultScript)
if err != nil { if err != nil {
return err return err
} }
@ -65,7 +51,7 @@ func isInitialized() bool {
return true return true
} }
func initialize(style Style) error { func initialize() error {
var err error var err error
if !isInitialized() { if !isInitialized() {
dir, err := os.Getwd() dir, err := os.Getwd()
@ -85,7 +71,7 @@ func initialize(style Style) error {
if err != nil { if err != nil {
return err return err
} }
err = dumpInitFiles(style) err = dumpInitFiles()
} }
return err return err
} }
@ -106,16 +92,9 @@ type initializeFlags struct {
} }
func Command() (goutil.CommandFlagsInit, goutil.CommandFunc) { func Command() (goutil.CommandFlagsInit, goutil.CommandFunc) {
f := initializeFlags{}
flagsInit := func(s *flag.FlagSet) { flagsInit := func(s *flag.FlagSet) {
s.StringVar(&f.style, "style", "minimal", "\"minimal\" or \"evil\" (Bootstrap)")
} }
return flagsInit, func([]string) error { return flagsInit, func([]string) error {
if f.style == "evil" { return initialize()
fmt.Println("You should feel bad, but anyway...")
return initialize(BSStarter)
} else {
return initialize(Minimal)
}
} }
} }

11
initer/script.go Normal file
View File

@ -0,0 +1,11 @@
package initer
const defaultScript string = `function retard() {
var x = document.getElementById("navigation");
if (x.className === "navigation") {
x.className += " retarded";
} else {
x.className = "navigation";
}
}
`

View File

@ -1,6 +1,6 @@
package initer package initer
var defaultStyle string = `body { const defaultStyle string = `body {
font-family: Arial,Helvetica,sans-serif; font-family: Arial,Helvetica,sans-serif;
font-size: 12pt; font-size: 12pt;
max-width: 750px; max-width: 750px;
@ -45,6 +45,33 @@ div.blogpost {
div.navigation { div.navigation {
padding-bottom: 0.5em; padding-bottom: 0.5em;
} }
.navigation .burger {
display:none;
padding: 14px 16px;
}
@media screen and not (min-width: 1024px) {
.navigation a {
display: none;
}
.navigation a.burger {
float: right;
display: block;
}
.navigation.retarded {
position: relative;
}
.navigation.retarded .burger {
position: absolute;
right: 0;
top: 0;
}
.navigation.retarded a {
float: none;
display: block;
text-align: left;
padding: 14px 16px;
}
}
blockquote { blockquote {
margin-left: 1em; margin-left: 1em;
margin-right: 0; margin-right: 0;
@ -70,14 +97,3 @@ td {
padding-right: .5em; padding-right: .5em;
} }
` `
/******************************************************************************/
var bsStarterStyle string = `body {
padding-top: 5rem;
}
.starter-template {
padding: 3rem 1.5rem;
text-align: justify;
}
`

View File

@ -1,6 +1,6 @@
package initer package initer
var rssTemplate string = `<?xml version="1.0" encoding="UTF-8"?> const defaultRSSTemplate string = `<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel> <channel>
<title>YOUR TITLE</title> <title>YOUR TITLE</title>
@ -22,7 +22,7 @@ var rssTemplate string = `<?xml version="1.0" encoding="UTF-8"?>
</rss> </rss>
` `
var defaultTemplate string = `<!DOCTYPE html> const defaultTemplate string = `<!DOCTYPE html>
<html> <html>
<head><title>{{.Title}}</title> <head><title>{{.Title}}</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
@ -32,18 +32,18 @@ var defaultTemplate string = `<!DOCTYPE html>
{{if or .PostCollection .Blogpost}} {{if or .PostCollection .Blogpost}}
<link rel="alternate" type="application/rss+xml" title="RSS" href="/{{.Blogdir}}/feed.rss"> <link rel="alternate" type="application/rss+xml" title="RSS" href="/{{.Blogdir}}/feed.rss">
{{end}} {{end}}
<style> <style>{{.Style}}</style>
{{.Style}} <script>{{.Script}}</script>
</style>
</head> </head>
<body> <body>
<h1>{{if .Blogpost}}{{.Blogname}}: {{end}}{{.Title}}</h1> <h1>{{if .Blogpost}}{{.Blogname}}: {{end}}{{.Title}}</h1>
<div class="navigation"> <div class="navigation" id="navigation">
<a href="/">home</a> <a href="/">home</a>
<a href="/blog/">blog</a> <a href="/blog/">blog</a>
<a href="/photos/pages/">photos</a> <a href="/photos/pages/">photos</a>
<a href="javascript:void(0);" class="burger" onclick="retard()"></a>
</div> </div>
{{if .Description}}<h3>{{.Description}}</h3>{{end}}
{{if .Subpages}} {{if .Subpages}}
<dl> <dl>
@ -52,7 +52,6 @@ var defaultTemplate string = `<!DOCTYPE html>
{{end}} {{end}}
</dl> </dl>
{{end}} {{end}}
{{if .Description}}<h3>{{.Description}}</h3>{{end}}
{{if .PostCollection}} {{if .PostCollection}}
<h2><a href="/{{.Blogdir}}/categories.html">Categories</a> &nbsp; &nbsp; <a href="/{{.Blogdir}}/timeline.html">Timeline</a></h2> <h2><a href="/{{.Blogdir}}/categories.html">Categories</a> &nbsp; &nbsp; <a href="/{{.Blogdir}}/timeline.html">Timeline</a></h2>
@ -125,136 +124,3 @@ var defaultTemplate string = `<!DOCTYPE html>
</body> </body>
</html> </html>
` `
/******************************************************************************/
// external JavaScript and CSS - definitely not recommended
var bsStarterTemplate string = `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- Tell "smart" phones that they are as wide as they are wide... -->
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
{{if or .PostCollection .Blogpost}}
<link rel="alternate" type="application/rss+xml" title="RSS" href="/{{.Blogdir}}/feed.rss">
{{end}}
<title>{{.Title}}</title>
<style>
{{.Style}}
</style>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
<a class="navbar-brand" href="/">Home</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item active"><a class="nav-link" href="/blog">Blog</a></li>
<li class="nav-item active"><a class="nav-link" href="/photos/pages/">Photos</a></li>
</li>
</ul>
</div>
</nav>
<main role="main" class="container">
<div class="starter-template">
<h1>{{if .Blogpost}}{{.Blogname}}: {{end}}{{.Title}}</h1>
{{if .Subpages}}
<dl>
{{range $index, $subpage := .Subpages}}
<dt><a href="/{{$subpage.Path}}">[{{$subpage.Title}}]</a></dt><dd>{{$subpage.Description}}</dd>
{{end}}
</dl>
{{end}}
{{if .Description}}<h3>{{.Description}}</h3>{{end}}
{{if .PostCollection }}
<h2><a href="/{{.Blogdir}}/categories.html">Categories</a> &nbsp; &nbsp; <a href="/{{.Blogdir}}/timeline.html">Timeline</a></h2>
{{range $index, $post := .PostCollection}}
<div class="blogpost">
<h1>
<a href ="{{$post.Link}}" class="linktopost">{{$post.Title}}</a>
</h1>
{{$post.Content}}
</div>
{{end}}
{{end}}
<div class="content">
{{.Content}}
{{if .CategoryListings}}
<div class="categoryListing">
<dl style="padding-bottom:150em;">
{{range $i, $listing := .CategoryListings -}}
<dt><a name="{{$listing.ASCIIName}}" class="categoryListing">{{$listing.Name}}</a></dt>
{{range $j, $post := $listing.Posts -}}
<dd><a href="{{$post.Link}}">{{$post.Meta.Title}}</a></dd>
{{end}}
{{end}}
</dl>
</div>
{{end}}
{{if .TimelineListing}}
<div class="timelineListing">
{{range $i, $post := .TimelineListing -}}
{{$post.Meta.FormattedDate}}: <a href="{{$post.Link}}" class="timelineListing">{{$post.Meta.Title}}</a><br>
{{end}}
</div>
{{end}}
</div>
{{if .Categories}}
<div class="categories">
Posted in
{{range $index, $category := .Categories}}
<a href="{{$category.Path}}">{{$category.Name}}</a>
{{end}}
</div>
{{end}}
{{if .Time}}
<div class="time">
{{.Time}} UTC
</div>
{{end}}
{{if or .Previous .Later}}
<div class="blognavigation">
{{if .Previous}}
<h2><a href="{{.Previous}}">&lt;--Previous</a></h2>
{{end}}
{{if .Later}}
<h2><a href="{{.Later}}"><h2>Later--&gt;</a></h2>
{{end}}
</div>
{{end}}
</div>
</main><!-- /.container -->
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.clownflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
`

View File

@ -4,13 +4,14 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"fmt" "fmt"
goutil "git.gutmet.org/goutil.git/misc"
. "git.gutmet.org/wombat.git/templatestructures"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"text/template" "text/template"
goutil "git.gutmet.org/goutil.git/misc"
. "git.gutmet.org/wombat.git/templatestructures"
) )
type metadata struct { type metadata struct {
@ -104,13 +105,14 @@ func getMetadata(path string) metadata {
return ret return ret
} }
func completePage(path string, t *template.Template, style string) { func completePage(path string, t *template.Template, style string, script string) {
md := getMetadata(path) md := getMetadata(path)
emd := md.explicit emd := md.explicit
content, _ := goutil.ReadFile(path) content, _ := goutil.ReadFile(path)
page := Page{} page := Page{}
page.Title = emd.title page.Title = emd.title
page.Style = style page.Style = style
page.Script = script
page.Subpages = md.getSubpages() page.Subpages = md.getSubpages()
page.Description = emd.description page.Description = emd.description
page.Content = content page.Content = content
@ -134,22 +136,26 @@ func ignore(path string) bool {
return false return false
} }
func traverse(t *template.Template, style string, path string, info os.FileInfo, err error) error { func traverse(t *template.Template, style string, script string, path string, info os.FileInfo, err error) error {
if !ignore(path) && isHTMLFile(path) && hasDescription(path) { if !ignore(path) && isHTMLFile(path) && hasDescription(path) {
completePage(path, t, style) completePage(path, t, style, script)
} }
return nil return nil
} }
func Generate() { func Generate() {
style, err := goutil.ReadFile("style.css") style, err := goutil.ReadFile("style.css")
templateString, err2 := goutil.ReadFile("template") script, err2 := goutil.ReadFile("script.js")
templateString, err3 := goutil.ReadFile("template")
t := template.Must(template.New("page").Parse(templateString)) t := template.Must(template.New("page").Parse(templateString))
traverseFunc := func(path string, info os.FileInfo, err error) error { return traverse(t, style, path, info, err) } traverseFunc := func(path string, info os.FileInfo, err error) error {
if err == nil && err2 == nil { return traverse(t, style, script, path, info, err)
}
if err == nil && err2 == nil && err3 == nil {
filepath.Walk("stage1", traverseFunc) filepath.Walk("stage1", traverseFunc)
} else { } else {
fmt.Println(err) fmt.Println(err)
fmt.Println(err2) fmt.Println(err2)
fmt.Println(err3)
} }
} }

View File

@ -7,6 +7,7 @@ import (
type Page struct { type Page struct {
Title string Title string
Style string Style string
Script string
Subpages []Subpage Subpages []Subpage
Description string Description string
Content string Content string