add default script for burger menu on retarded devices
This commit is contained in:
parent
dac343fa51
commit
59a11a0882
12
blog/blog.go
12
blog/blog.go
|
@ -22,6 +22,7 @@ const postsPerPage int = 5
|
|||
var blogname string
|
||||
var folder string
|
||||
var style string
|
||||
var script string
|
||||
var t *template.Template
|
||||
var rssTemplate *template.Template
|
||||
var categories map[string][]Post
|
||||
|
@ -66,6 +67,7 @@ func emitPostPage(post Post) string {
|
|||
page.Blogdir = folder
|
||||
page.Title = post.Meta.Title
|
||||
page.Style = style
|
||||
page.Script = script
|
||||
page.Content = post.Content
|
||||
page.Time = post.Meta.Date.Format(TimeFormat)
|
||||
page.Blogpost = true
|
||||
|
@ -110,6 +112,7 @@ func emitIndexPage(i int, posts []Post, total int) {
|
|||
page := Page{}
|
||||
page.Title = blogname
|
||||
page.Style = style
|
||||
page.Script = script
|
||||
page.Blogdir = folder
|
||||
page.Blogname = blogname
|
||||
page.Blogpost = false
|
||||
|
@ -180,6 +183,7 @@ func makeCategories() {
|
|||
page := Page{}
|
||||
page.Title = blogname + ": Categories"
|
||||
page.Style = style
|
||||
page.Script = script
|
||||
keySet := keys(categories)
|
||||
sort.Strings(keySet)
|
||||
for _, k := range keySet {
|
||||
|
@ -200,6 +204,7 @@ func makeTimeline(posts []Post) {
|
|||
page := Page{}
|
||||
page.Title = blogname + ": Timeline"
|
||||
page.Style = style
|
||||
page.Script = script
|
||||
page.TimelineListing = posts
|
||||
buf := new(bytes.Buffer)
|
||||
t.Execute(buf, page)
|
||||
|
@ -269,15 +274,18 @@ func Generate(dir string) {
|
|||
categories = make(map[string][]Post)
|
||||
var err error
|
||||
var err2 error
|
||||
var err3 error
|
||||
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))
|
||||
rssTemplateString, _ := goutil.ReadFile("rssTemplate")
|
||||
rssTemplate = template.Must(template.New("rss").Parse(rssTemplateString))
|
||||
if err == nil && err2 == nil {
|
||||
if err == nil && err2 == nil && err3 == nil {
|
||||
makeBlog()
|
||||
} else {
|
||||
fmt.Println(err)
|
||||
fmt.Println(err2)
|
||||
fmt.Println(err3)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,48 +4,34 @@ import (
|
|||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
finstr "git.gutmet.org/finstr.git/initer"
|
||||
goutil "git.gutmet.org/goutil.git/misc"
|
||||
"git.gutmet.org/wombat.git/gallery"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const (
|
||||
initflag = ".wombat"
|
||||
)
|
||||
|
||||
type Style int
|
||||
var checkpaths []string = []string{initflag, "stage0", "template", "style.css", "script.js"}
|
||||
|
||||
const (
|
||||
Minimal Style = 0
|
||||
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)
|
||||
func dumpInitFiles() error {
|
||||
err := goutil.WriteFile("template", defaultTemplate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = goutil.WriteFile("rssTemplate", rssTemplate)
|
||||
err = goutil.WriteFile("rssTemplate", defaultRSSTemplate)
|
||||
if err != nil {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
@ -65,7 +51,7 @@ func isInitialized() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func initialize(style Style) error {
|
||||
func initialize() error {
|
||||
var err error
|
||||
if !isInitialized() {
|
||||
dir, err := os.Getwd()
|
||||
|
@ -85,7 +71,7 @@ func initialize(style Style) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = dumpInitFiles(style)
|
||||
err = dumpInitFiles()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
@ -106,16 +92,9 @@ type initializeFlags struct {
|
|||
}
|
||||
|
||||
func Command() (goutil.CommandFlagsInit, goutil.CommandFunc) {
|
||||
f := initializeFlags{}
|
||||
flagsInit := func(s *flag.FlagSet) {
|
||||
s.StringVar(&f.style, "style", "minimal", "\"minimal\" or \"evil\" (Bootstrap)")
|
||||
}
|
||||
return flagsInit, func([]string) error {
|
||||
if f.style == "evil" {
|
||||
fmt.Println("You should feel bad, but anyway...")
|
||||
return initialize(BSStarter)
|
||||
} else {
|
||||
return initialize(Minimal)
|
||||
}
|
||||
return initialize()
|
||||
}
|
||||
}
|
||||
|
|
11
initer/script.go
Normal file
11
initer/script.go
Normal 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";
|
||||
}
|
||||
}
|
||||
`
|
|
@ -1,6 +1,6 @@
|
|||
package initer
|
||||
|
||||
var defaultStyle string = `body {
|
||||
const defaultStyle string = `body {
|
||||
font-family: Arial,Helvetica,sans-serif;
|
||||
font-size: 12pt;
|
||||
max-width: 750px;
|
||||
|
@ -45,6 +45,33 @@ div.blogpost {
|
|||
div.navigation {
|
||||
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 {
|
||||
margin-left: 1em;
|
||||
margin-right: 0;
|
||||
|
@ -70,14 +97,3 @@ td {
|
|||
padding-right: .5em;
|
||||
}
|
||||
`
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
var bsStarterStyle string = `body {
|
||||
padding-top: 5rem;
|
||||
}
|
||||
.starter-template {
|
||||
padding: 3rem 1.5rem;
|
||||
text-align: justify;
|
||||
}
|
||||
`
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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/">
|
||||
<channel>
|
||||
<title>YOUR TITLE</title>
|
||||
|
@ -22,7 +22,7 @@ var rssTemplate string = `<?xml version="1.0" encoding="UTF-8"?>
|
|||
</rss>
|
||||
`
|
||||
|
||||
var defaultTemplate string = `<!DOCTYPE html>
|
||||
const defaultTemplate string = `<!DOCTYPE html>
|
||||
<html>
|
||||
<head><title>{{.Title}}</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
||||
|
@ -32,18 +32,18 @@ var defaultTemplate string = `<!DOCTYPE html>
|
|||
{{if or .PostCollection .Blogpost}}
|
||||
<link rel="alternate" type="application/rss+xml" title="RSS" href="/{{.Blogdir}}/feed.rss">
|
||||
{{end}}
|
||||
<style>
|
||||
{{.Style}}
|
||||
</style>
|
||||
<style>{{.Style}}</style>
|
||||
<script>{{.Script}}</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>{{if .Blogpost}}{{.Blogname}}: {{end}}{{.Title}}</h1>
|
||||
<div class="navigation">
|
||||
<div class="navigation" id="navigation">
|
||||
<a href="/">home</a>
|
||||
<a href="/blog/">blog</a>
|
||||
<a href="/photos/pages/">photos</a>
|
||||
<a href="javascript:void(0);" class="burger" onclick="retard()">☰</a>
|
||||
</div>
|
||||
{{if .Description}}<h3>{{.Description}}</h3>{{end}}
|
||||
|
||||
{{if .Subpages}}
|
||||
<dl>
|
||||
|
@ -52,7 +52,6 @@ var defaultTemplate string = `<!DOCTYPE html>
|
|||
{{end}}
|
||||
</dl>
|
||||
{{end}}
|
||||
{{if .Description}}<h3>{{.Description}}</h3>{{end}}
|
||||
|
||||
{{if .PostCollection}}
|
||||
<h2><a href="/{{.Blogdir}}/categories.html">Categories</a> <a href="/{{.Blogdir}}/timeline.html">Timeline</a></h2>
|
||||
|
@ -125,136 +124,3 @@ var defaultTemplate string = `<!DOCTYPE html>
|
|||
</body>
|
||||
</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> <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}}"><--Previous</a></h2>
|
||||
{{end}}
|
||||
{{if .Later}}
|
||||
<h2><a href="{{.Later}}"><h2>Later--></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>
|
||||
`
|
||||
|
|
22
site/site.go
22
site/site.go
|
@ -4,13 +4,14 @@ import (
|
|||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
goutil "git.gutmet.org/goutil.git/misc"
|
||||
. "git.gutmet.org/wombat.git/templatestructures"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
goutil "git.gutmet.org/goutil.git/misc"
|
||||
. "git.gutmet.org/wombat.git/templatestructures"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
|
@ -104,13 +105,14 @@ func getMetadata(path string) metadata {
|
|||
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)
|
||||
emd := md.explicit
|
||||
content, _ := goutil.ReadFile(path)
|
||||
page := Page{}
|
||||
page.Title = emd.title
|
||||
page.Style = style
|
||||
page.Script = script
|
||||
page.Subpages = md.getSubpages()
|
||||
page.Description = emd.description
|
||||
page.Content = content
|
||||
|
@ -134,22 +136,26 @@ func ignore(path string) bool {
|
|||
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) {
|
||||
completePage(path, t, style)
|
||||
completePage(path, t, style, script)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Generate() {
|
||||
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))
|
||||
traverseFunc := func(path string, info os.FileInfo, err error) error { return traverse(t, style, path, info, err) }
|
||||
if err == nil && err2 == nil {
|
||||
traverseFunc := func(path string, info os.FileInfo, err error) error {
|
||||
return traverse(t, style, script, path, info, err)
|
||||
}
|
||||
if err == nil && err2 == nil && err3 == nil {
|
||||
filepath.Walk("stage1", traverseFunc)
|
||||
} else {
|
||||
fmt.Println(err)
|
||||
fmt.Println(err2)
|
||||
fmt.Println(err3)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
type Page struct {
|
||||
Title string
|
||||
Style string
|
||||
Script string
|
||||
Subpages []Subpage
|
||||
Description string
|
||||
Content string
|
||||
|
|
Loading…
Reference in New Issue
Block a user