remove static pages content

This commit is contained in:
Erik Winter 2020-12-04 16:52:25 +01:00
parent 4a864924fc
commit 29e8cd0422
14 changed files with 50 additions and 80 deletions

15
main.go
View File

@ -2,6 +2,7 @@ package main
import (
"flag"
"io/ioutil"
"log"
"os"
"path/filepath"
@ -13,12 +14,13 @@ import (
var (
resources = flag.String("resources", "./resources", "folder with templates and other resources")
content = flag.String("content", "./content,/projectx", "comma separated list of folders search for content")
statics = flag.String("statics", "./statics", "folder with static content")
public = flag.String("public", "./public", "target folder for generated site")
)
func main() {
flag.Parse()
if *resources == "" || *content == "" || *public == "" {
if *resources == "" || *content == "" || *public == "" || *statics == "" {
log.Fatal("missing parameter")
}
@ -28,6 +30,17 @@ func main() {
log.Fatal(err)
}
// add statics
staticNames, err := ioutil.ReadDir(*statics)
if err != nil {
log.Fatal(err)
}
for _, sn := range staticNames {
if sn.IsDir() {
s.AddStaticPage(filepath.Join(*statics, sn.Name()))
}
}
// add content
for _, cp := range strings.Split(*content, ",") {
log.Printf("checking %s for content\n", cp)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 870 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

View File

@ -1,19 +0,0 @@
<!DOCTYPE html>
<html>
{{- template "head" . -}}
<body>
{{- template "menu" -}}
<main>
<article>
<h2 id="hi">Hi,</h2>
<p>As you may have guessed from the contents of this site, I am a Dutch software developer who also likes literature and music and a bunch of other things.</p>
<p>I am old enough to remember what the internet was like before platforms like Facebook, Twitter, Github, etc. came around. Everything was decentralized, everybody had their own website and it actually felt more personal and real than the &ldquo;social&rdquo; media of today.</p>
<p>Since I like to create things, I thought I&rsquo;d make myself an old school personal website again. For my own pleasure. And for others like me. I know you are out there!</p>
<h2 id="rss-feeds">RSS Feeds</h2>
<p>To stay updated, there is an RSS link: <a href="/index.xml"><img src="rss.png" alt="RSS Icon">Recent</a></p>
<h2 id="contact">Contact</h2>
<p>I'm <a href="https://fosstodon.org/@ewintr">@ewintr@fosstodon.org</a> on Mastodon.</p>
<p>Otherwise, you can contact me by sending me an <a href="mailto:info@erikwinter.nl">email</a>.</p>
</article>
</main>
</body>

View File

@ -1,37 +0,0 @@
<!DOCTYPE html>
<html>
{{- template "head" . -}}
<body>
{{- template "menu" -}}
<main>
<article>
<section class="greybox-light">
<p><a href="https://crunchygranola.nl"><img src="crunchy.jpeg" alt="Crunchy Granola logo"></a></p>
<p>A <a href="https://crunchygranola.nl/">site</a> 🇳🇱 full of recipes for crunchy, tasty granolas that are nothing like the mundane stuff you buy at the store. Everything made from scratch, healthy ingredients, with options for all kinds of diets like gluten-free and keto. All recipes, photos, texts and design created by my wonderful girlfriend. I <em>-eh-</em> also did things.</p>
</section>
<section class="greybox-dark">
<p><img src="volca.png" alt="Volca Keys"></p>
<p>Some sounds I made. Some time ago.</p>
<audio controls>
<source src="christel%2039.mp3" type="audio/mp3">
</audio>
<audio controls>
<source src="werkeloos.mp3" type="audio/mp3">
</audio>
<audio controls>
<source src="volca%20testje.mp3" type="audio/mp3">
</audio>
</section>
<section class="greybox-light">
<p><a href="https://lowlands.nl/schrijfwedstrijd"><img src="lowlandswedstrijd.jpg" alt="Story illustration"></a></p>
<p>In 2015, one of my stories won the Lowlands Short Story contest. Because of that, it was featured in NRC, a Dutch national newspaper. You can read it <a href="https://www.nrc.nl/nieuws/2015/08/24/het-korte-nare-leven-van-arnold-scheepmaker-1526148-a1387897">here</a> 🇳🇱 on their site.</p>
</section>
<section class="greybox-dark">
<p><a href="https://web.archive.org/web/20121105034629/http://www.beginnenmetroken.nl/"><img src="beginnenmetroken.jpg" alt="Logo Beginnenmetroken.nl"></a></p>
<p>A long time ago, somewhere at the start of this century, I created <a href="http://www.BeginnenMetRoken.nl">www.BeginnenMetRoken.nl</a>, a satirical site that &ldquo;helped&rdquo; people to kickstart their smoking habit. Right in the middle of large campaings urging people to quit, it struck a nerve and went viral. Millions of pageviews, featured in several magazines. People still bring it up, twenty years later.</p>
<p>The site is gone, but it you can still view it <a href="https://web.archive.org/web/20121105034629/http://www.beginnenmetroken.nl/">here 🇳🇱</a> on Archive.org.</p>
</section>
</article>
</main>
</body>
</html>

View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
{{- template "head" . -}}
<body>
{{- template "menu" -}}
<main>
{{- .MainHTML -}}
</main>
</body>

View File

@ -33,7 +33,7 @@ func moveResources(targetPath, resourcesPath string) error {
return nil
}
func renderStaticPages(targetPath string, statics []*StaticPage) error {
func renderStaticPages(targetPath string, tpl *template.Template, statics []*StaticPage) error {
for _, static := range statics {
destPath := filepath.Join(targetPath, static.Name)
if err := os.MkdirAll(destPath, dirMode); err != nil {
@ -45,16 +45,23 @@ func renderStaticPages(targetPath string, statics []*StaticPage) error {
}
defer pageFile.Close()
data := struct {
Title string
}{
Title: strings.Title(static.Name),
}
if err := static.Template.Execute(pageFile, data); err != nil {
mainHTML, err := ioutil.ReadFile(filepath.Join(static.Path, "main.html"))
if err != nil {
return err
}
if err := copyFiles(filepath.Join(static.SourcePath, "*"), destPath); err != nil {
data := struct {
Title string
Main string
}{
Title: strings.Title(static.Name),
Main: string(mainHTML),
}
if err := tpl.Execute(pageFile, data); err != nil {
return err
}
if err := copyFiles(filepath.Join(static.Path, "resources", "*"), destPath); err != nil {
return err
}
}

View File

@ -9,8 +9,7 @@ import (
type StaticPage struct {
Name string
Template *template.Template
SourcePath string
Path string
}
type Site struct {
@ -26,23 +25,21 @@ func New(resourcesPath string) (*Site, error) {
return &Site{}, err
}
staticPages := []*StaticPage{}
for _, stName := range []string{"other", "about"} {
staticPages = append(staticPages, &StaticPage{
Name: stName,
Template: templates[stName],
SourcePath: filepath.Join(resourcesPath, stName),
})
}
return &Site{
resourcesPath: resourcesPath,
templates: templates,
posts: []Post{},
staticPages: staticPages,
staticPages: []*StaticPage{},
}, nil
}
func (s *Site) AddStaticPage(staticPath string) {
s.staticPages = append(s.staticPages, &StaticPage{
Name: filepath.Base(staticPath),
Path: staticPath,
})
}
func (s *Site) AddFilePost(fPath string) error {
content, err := ioutil.ReadFile(fPath)
if err != nil {
@ -67,7 +64,7 @@ func (s *Site) RenderHTML(targetPath string) error {
if err := moveResources(targetPath, s.resourcesPath); err != nil {
return err
}
if err := renderStaticPages(targetPath, s.staticPages); err != nil {
if err := renderStaticPages(targetPath, s.templates["static"], s.staticPages); err != nil {
return err
}
@ -96,7 +93,7 @@ func (s *Site) RenderHTML(targetPath string) error {
func parseTemplates(resourcesPath string) (map[string]*template.Template, error) {
templates := map[string]*template.Template{}
tPath := filepath.Join(resourcesPath, "template")
for _, tName := range []string{"post", "list", "archive", "other", "about"} {
for _, tName := range []string{"post", "list", "archive", "static"} {
var tFiles []string
for _, tf := range []string{tName, "head", "menu"} {
tFiles = append(tFiles, filepath.Join(tPath, fmt.Sprintf("%s.gohtml", tf)))