Skip to content

Commit 3159da2

Browse files
committed
2 parents 3fd0a49 + a6333f2 commit 3159da2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+57531
-35
lines changed

.github/workflows/hugo.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,7 @@ jobs:
5757
HUGO_ENV: production
5858
TZ: America/Los_Angeles
5959
run: |
60-
hugo \
61-
--gc \
62-
--minify \
63-
--baseURL "${{ steps.pages.outputs.base_url }}/"
64-
&& cd public/en
65-
&& cp 404.html ../404.html
60+
hugo --gc --minify --baseURL "${{ steps.pages.outputs.base_url }}/" && cd public/en && cp 404.html ../404.html
6661
- name: Upload artifact
6762
uses: actions/upload-pages-artifact@v3
6863
with:

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
Blog: https://d-oit.github.io/
1+
Personal Blog: https://d-oit.github.io/
2+
3+
**Status**
4+
5+
[![🧪 Playwright End To End (e2e) Tests Workflow](https://github.com/d-oit/d-oit.github.io/actions/workflows/playwright.yml/badge.svg)](https://github.com/d-oit/d-oit.github.io/actions/workflows/playwright.yml)
6+
7+
[![Update Google Calendar Basket Calendar as JSON](https://github.com/d-oit/d-oit.github.io/actions/workflows/update_free_basket_calendar.yml/badge.svg)](https://github.com/d-oit/d-oit.github.io/actions/workflows/update_free_basket_calendar.yml)
8+
9+
[![Deploy Hugo site to Pages](https://github.com/d-oit/d-oit.github.io/actions/workflows/hugo.yaml/badge.svg)](https://github.com/d-oit/d-oit.github.io/actions/workflows/hugo.yaml)
10+
211

312
WIP - try new things with Hugo CMS / Hinode Theme / Markdown / GitHub
413

514

15+
616
Create a new issue if you find a problem of the website: https://github.com/d-oit/d-oit.github.io/issues
717

818
Any questions: https://github.com/d-oit/d-oit.github.io/discussions
19+
20+
21+

adminEditor/config.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"shortcodes": {
3+
"bold": "**bold**",
4+
"italic": "_italic_",
5+
"link": "[link text](url)",
6+
"code": "`code`",
7+
"image": "![alt text](image_url)",
8+
"file": "{{< file full=\"false\" path=\"./config/_default/languages.toml\" id=\"file-collapse-1\" >}}"
9+
},
10+
"icons": {
11+
"bold": "bold",
12+
"italic": "italic",
13+
"link": "link",
14+
"code": "code",
15+
"image": "image",
16+
"file": "file"
17+
},
18+
"server": {
19+
"port": 8081,
20+
"showURLOnStart": true,
21+
"germanFolder": "E:/git/d-oit/blog/d-oit.github.io/content/de/blog",
22+
"englishFolder": "E:/git/d-oit/blog/d-oit.github.io/content/en/blog"
23+
}
24+
}

adminEditor/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module markdown-editor
2+
3+
go 1.23.1

adminEditor/main.go

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"io/ioutil"
7+
"log"
8+
"net/http"
9+
"os"
10+
"path/filepath"
11+
"strings"
12+
)
13+
14+
type ShortcodeConfig struct {
15+
Shortcodes map[string]string `json:"shortcodes"`
16+
Icons map[string]string `json:"icons"`
17+
}
18+
19+
type ServerConfig struct {
20+
Port int `json:"port"`
21+
ShowURLOnStart bool `json:"showURLOnStart"`
22+
GermanFolder string `json:"germanFolder"`
23+
EnglishFolder string `json:"englishFolder"`
24+
}
25+
26+
type Config struct {
27+
// Shortcodes ShortcodeConfig `json:"shortcodes"`
28+
Shortcodes map[string]string `json:"shortcodes"`
29+
Icons map[string]string `json:"icons"`
30+
Server ServerConfig `json:"server"`
31+
}
32+
33+
var config Config
34+
35+
func main() {
36+
// Load configuration
37+
loadConfig()
38+
39+
// Serve static files
40+
fs := http.FileServer(http.Dir("static"))
41+
http.Handle("/", fs)
42+
43+
// API endpoints
44+
http.HandleFunc("/api/config", handleConfig)
45+
http.HandleFunc("/api/save", handleSave)
46+
http.HandleFunc("/api/load", handleLoad)
47+
http.HandleFunc("/api/list", handleList)
48+
49+
// Determine the address to listen on
50+
addr := fmt.Sprintf(":%d", config.Server.Port)
51+
52+
// Show URL on start if configured
53+
if config.Server.ShowURLOnStart {
54+
log.Printf("Server starting on http://localhost%s", addr)
55+
} else {
56+
log.Printf("Server starting on port %d", config.Server.Port)
57+
}
58+
59+
log.Fatal(http.ListenAndServe(addr, nil))
60+
}
61+
62+
func loadConfig() {
63+
file, err := ioutil.ReadFile("config.json")
64+
if err != nil {
65+
log.Fatal("Error reading config file:", err)
66+
}
67+
68+
err = json.Unmarshal(file, &config)
69+
if err != nil {
70+
log.Fatal("Error parsing config file:", err)
71+
}
72+
73+
// Set default values if not specified
74+
if config.Server.Port == 0 {
75+
config.Server.Port = 8080
76+
}
77+
if config.Server.GermanFolder == "" {
78+
config.Server.GermanFolder = "/content/de/blog"
79+
}
80+
if config.Server.EnglishFolder == "" {
81+
config.Server.EnglishFolder = "/content/en/blog"
82+
}
83+
84+
// Convert relative paths to absolute paths
85+
absPath, err := filepath.Abs(config.Server.GermanFolder)
86+
if err == nil {
87+
config.Server.GermanFolder = absPath
88+
}
89+
absPath, err = filepath.Abs(config.Server.EnglishFolder)
90+
if err == nil {
91+
config.Server.EnglishFolder = absPath
92+
}
93+
}
94+
95+
func handleConfig(w http.ResponseWriter, r *http.Request) {
96+
w.Header().Set("Content-Type", "application/json")
97+
json.NewEncoder(w).Encode(config)
98+
}
99+
100+
func handleSave(w http.ResponseWriter, r *http.Request) {
101+
if r.Method != http.MethodPost {
102+
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
103+
return
104+
}
105+
106+
filename := r.URL.Query().Get("file")
107+
if filename == "" {
108+
http.Error(w, "Filename is required", http.StatusBadRequest)
109+
return
110+
}
111+
112+
content, err := ioutil.ReadAll(r.Body)
113+
if err != nil {
114+
http.Error(w, "Error reading request body", http.StatusInternalServerError)
115+
return
116+
}
117+
118+
fullPath := getFullPath(filename)
119+
err = ioutil.WriteFile(fullPath, content, 0644)
120+
if err != nil {
121+
http.Error(w, "Error saving file", http.StatusInternalServerError)
122+
return
123+
}
124+
125+
w.WriteHeader(http.StatusOK)
126+
}
127+
128+
func handleLoad(w http.ResponseWriter, r *http.Request) {
129+
filename := r.URL.Query().Get("file")
130+
if filename == "" {
131+
http.Error(w, "Filename is required", http.StatusBadRequest)
132+
return
133+
}
134+
135+
fullPath := getFullPath(filename)
136+
content, err := ioutil.ReadFile(fullPath)
137+
if err != nil {
138+
if os.IsNotExist(err) {
139+
http.Error(w, "File not found", http.StatusNotFound)
140+
} else {
141+
http.Error(w, "Error reading file", http.StatusInternalServerError)
142+
}
143+
return
144+
}
145+
146+
w.Header().Set("Content-Type", "text/plain")
147+
w.Write(content)
148+
}
149+
150+
func handleList(w http.ResponseWriter, r *http.Request) {
151+
files := make(map[string][]string)
152+
153+
germanFiles, err := listFiles(config.Server.GermanFolder)
154+
if err != nil {
155+
http.Error(w, "Error reading German directory", http.StatusInternalServerError)
156+
return
157+
}
158+
files["de"] = germanFiles
159+
160+
englishFiles, err := listFiles(config.Server.EnglishFolder)
161+
if err != nil {
162+
http.Error(w, "Error reading English directory", http.StatusInternalServerError)
163+
return
164+
}
165+
files["en"] = englishFiles
166+
167+
w.Header().Set("Content-Type", "application/json")
168+
json.NewEncoder(w).Encode(files)
169+
}
170+
171+
func listFiles(dir string) ([]string, error) {
172+
var files []string
173+
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
174+
if err != nil {
175+
return err
176+
}
177+
if !info.IsDir() && strings.HasSuffix(info.Name(), ".md") {
178+
relPath, err := filepath.Rel(dir, path)
179+
if err != nil {
180+
return err
181+
}
182+
files = append(files, relPath)
183+
}
184+
return nil
185+
})
186+
return files, err
187+
}
188+
189+
func getFullPath(filename string) string {
190+
parts := strings.SplitN(filename, "/", 2)
191+
if len(parts) != 2 {
192+
return filename
193+
}
194+
195+
lang, file := parts[0], parts[1]
196+
switch lang {
197+
case "de":
198+
return filepath.Join(config.Server.GermanFolder, file)
199+
case "en":
200+
return filepath.Join(config.Server.EnglishFolder, file)
201+
default:
202+
return filename
203+
}
204+
}

0 commit comments

Comments
 (0)