improvement of the code, to create better readability and error correction. moving to v1.1.0
This commit is contained in:
@@ -10,7 +10,8 @@ import (
|
||||
|
||||
var data_articles_index string = ""
|
||||
var top string = "<!doctype html><html lang='en'><head><meta charset='UTF-8' /><meta name='viewport' content='width=device-width, initial-scale=1.0' /><title>Haufenet</title><link rel='stylesheet' href='/index.css' /><link rel='icon' type='image/png' href='/favicon-96x96.png' sizes='96x96'/><link rel='icon' type='image/svg+xml' href='/favicon.svg'/><link rel='shortcut icon' href='/favicon.ico' /><link rel='apple-touch-icon' sizes='180x180' href='/apple-touch-icon.png' /><link rel='manifest' href='/site.webmanifest' /><link rel='preconnect' href='https://fonts.googleapis.com'><link rel='preconnect' href='https://fonts.gstatic.com' crossorigin><link href='https://fonts.googleapis.com/css2?family=BBH+Bogle&display=swap' rel='stylesheet'></head><body><header><a href='/' ><b>Haufenet</b></a></header>"
|
||||
var bottom string = "<footer><p>© Lennard Haufe<p><p>No usage of AI</p><a href='/imprint_privacy/'>Imprint and Privacy</a></footer></body><script src='/index.js'></script></html>"
|
||||
var bottom string = "<footer><p>© Lennard Haufe<p><p>Running on net/http GO</p><p>No usage of AI</p><a href='/imprint_privacy/'>Imprint and Privacy</a></footer></body><script src='/index.js'></script></html>"
|
||||
var tag_collection string = ""
|
||||
|
||||
func main() {
|
||||
entries, err := os.ReadDir("./articles")
|
||||
@@ -18,14 +19,14 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for _, e := range entries {
|
||||
|
||||
ReadFileArticles(e.Name())
|
||||
SetupDataIndexArticles(e.Name())
|
||||
AnalayzeFiles(e.Name())
|
||||
}
|
||||
log.Println(tag_collection)
|
||||
log.Print("Server running on port 8090")
|
||||
EditArticlesPage()
|
||||
ReadFileOthers("imprint_privacy.md")
|
||||
fileserver := http.FileServer(http.Dir("./website"))
|
||||
|
||||
http.Handle("/", fileserver)
|
||||
|
||||
if err := http.ListenAndServe(":8090", nil); err != nil {
|
||||
@@ -40,103 +41,72 @@ func EditArticlesPage() {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
func SetupDataIndexArticles(filename string) {
|
||||
|
||||
func AnalayzeFiles(filename string) {
|
||||
file, err := os.Open("./articles/" + filename)
|
||||
if err != nil {
|
||||
log.Fatalf("not opening")
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
var title string = ""
|
||||
var description string = ""
|
||||
var tags string = ""
|
||||
var image string = ""
|
||||
for scanner.Scan() {
|
||||
content := scanner.Text()
|
||||
if strings.Contains(content, "###") {
|
||||
continue
|
||||
} else if strings.Contains(content, "##") {
|
||||
continue
|
||||
} else if strings.Contains(content, "#") {
|
||||
part := strings.Split(content, `#`)
|
||||
title = "<h1>" + part[1] + "</h1>"
|
||||
} else if strings.Contains(content, "DESCRIPTION:") {
|
||||
part := strings.Split(content, `DESCRIPTION:`)
|
||||
description = "<p>" + part[1] + "</p>"
|
||||
} else if strings.Contains(content, "HEADIMAGE:") {
|
||||
part := strings.Split(content, `HEADIMAGE:`)
|
||||
image = "<img src='/pictures/" + part[1] + "'>"
|
||||
} else if strings.Contains(content, "TAGS:") {
|
||||
part := strings.Split(content, `TAGS:`)
|
||||
part_2 := strings.Split(part[1], ",")
|
||||
part_tags := "<articles-tags>"
|
||||
for i := 0; i < len(part_2); i++ {
|
||||
part_tags += "<a href='/tags/" + part_2[i] + "'>" + part_2[i] + "</a>"
|
||||
}
|
||||
part_tags += "</articles-tags>"
|
||||
tags = part_tags
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
filename_new := strings.Split(filename, ".md")
|
||||
data_articles_index += "<article-display><a href='/articles/" + filename_new[0] + ".html'>" + title + image + description + "</a>" + tags + "</article-display>"
|
||||
|
||||
}
|
||||
|
||||
func ReadFileArticles(filename string) {
|
||||
file, err := os.Open("./articles/" + filename)
|
||||
if err != nil {
|
||||
log.Fatalf("not opening")
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
var new_text string = ""
|
||||
var tags string = ""
|
||||
var end_text_page_article string = ""
|
||||
var tags_page_article string = ""
|
||||
var title_overview_articles string = ""
|
||||
var description_overview_articles string = ""
|
||||
var image_overview_articles string = ""
|
||||
for scanner.Scan() {
|
||||
content := scanner.Text()
|
||||
var end_type string = ""
|
||||
|
||||
if strings.Contains(content, "###") {
|
||||
part := strings.Split(content, `###`)
|
||||
end_type = "<h3>" + part[1] + "</h3>"
|
||||
end_text_page_article += "<h3>" + part[1] + "</h3>"
|
||||
} else if strings.Contains(content, "##") {
|
||||
part := strings.Split(content, `##`)
|
||||
end_type = "<h2>" + part[1] + "</h2>"
|
||||
end_text_page_article += "<h2>" + part[1] + "</h2>"
|
||||
} else if strings.Contains(content, "#") {
|
||||
part := strings.Split(content, `#`)
|
||||
end_type = "<h1>" + part[1] + "</h1>"
|
||||
end_text_page_article += "<h1>" + part[1] + "</h1>"
|
||||
title_overview_articles = "<h1>" + part[1] + "</h1>"
|
||||
} else if strings.Contains(content, "HEADIMAGE:") {
|
||||
part := strings.Split(content, `HEADIMAGE:`)
|
||||
end_type = "<img src='/pictures/" + part[1] + "'>"
|
||||
end_text_page_article += "<img src='/pictures/" + part[1] + "'>"
|
||||
image_overview_articles = "<img src='/pictures/" + part[1] + "'>"
|
||||
} else if strings.Contains(content, "DESCRIPTION:") {
|
||||
part := strings.Split(content, `DESCRIPTION:`)
|
||||
description_overview_articles = "<p>" + part[1] + "</p>"
|
||||
} else if strings.Contains(content, "[img]:") {
|
||||
part := strings.Split(content, `[img]:`)
|
||||
end_type = "<img src='/pictures/" + part[1] + "'>"
|
||||
end_text_page_article += "<img src='/pictures/" + part[1] + "'>"
|
||||
} else if strings.Contains(content, "DESCRIPTION:") {
|
||||
end_type = ""
|
||||
|
||||
end_text_page_article = ""
|
||||
} else if strings.Contains(content, "TAGS:") {
|
||||
part := strings.Split(content, `TAGS:`)
|
||||
part_2 := strings.Split(part[1], ",")
|
||||
part_tags := "<articles-tags>"
|
||||
for i := 0; i < len(part_2); i++ {
|
||||
part_tags += "<a href='/tags/" + part_2[i] + "'>" + part_2[i] + "</a>"
|
||||
tag_collection += "#" + part_2[i] + ":" + filename_new[0] + ":" + title_overview_articles + ":" + description_overview_articles + ":" + image_overview_articles
|
||||
}
|
||||
part_tags += "</articles-tags>"
|
||||
tags = part_tags
|
||||
tags_page_article = part_tags
|
||||
} else if content == "" {
|
||||
end_type = "<br>"
|
||||
end_text_page_article += "<br>"
|
||||
} else {
|
||||
end_type = "<p>" + content + "</p>"
|
||||
end_text_page_article += "<p>" + content + "</p>"
|
||||
}
|
||||
new_text += end_type
|
||||
|
||||
}
|
||||
filename_new := strings.Split(filename, ".md")
|
||||
err = os.WriteFile("./website/articles/"+filename_new[0]+".html", []byte(top+"<articles-detail><articles-detail-down>"+new_text+"<h4>Tags</h4>"+tags+"<br></articles-detail-down></articles-detail>"+bottom), 0755)
|
||||
|
||||
Page_Article(filename_new[0], end_text_page_article, tags_page_article)
|
||||
Page_Collection_Overview_Articles(filename_new[0], title_overview_articles, image_overview_articles, description_overview_articles, tags_page_article)
|
||||
|
||||
}
|
||||
func Page_Collection_Overview_Articles(filename string, title string, image string, description string, tags string) {
|
||||
data_articles_index += "<article-display><a href='/articles/" + filename + ".html'>" + title + image + description + "</a>" + tags + "</article-display>"
|
||||
}
|
||||
func Page_Article(filename string, text string, tags string) {
|
||||
err := os.WriteFile("./website/articles/"+filename+".html", []byte(top+"<articles-detail><articles-detail-down>"+text+"<h4>Tags</h4>"+tags+"<br></articles-detail-down></articles-detail>"+bottom), 0755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user