mirror of
https://git.davidovski.xyz/kblg.git
synced 2024-08-15 00:43:36 +00:00
initial commit
This commit is contained in:
commit
e0afc82688
10 changed files with 161 additions and 0 deletions
88
build.py
Normal file
88
build.py
Normal file
|
@ -0,0 +1,88 @@
|
|||
import markdown
|
||||
import os
|
||||
import time
|
||||
import shutil
|
||||
|
||||
from const import *
|
||||
|
||||
def getTemplateHTML(name):
|
||||
html = ""
|
||||
with open(os.path.join(templates, name), "r") as file:
|
||||
html = file.read();
|
||||
return html
|
||||
|
||||
def listPages():
|
||||
return [
|
||||
(lambda path:
|
||||
(lambda content:
|
||||
(lambda timestamp:
|
||||
(lambda name: {
|
||||
"source_file" : path,
|
||||
"source_content" : content,
|
||||
"html" : markdown.markdown(content),
|
||||
"timestamp" : timestamp,
|
||||
"date": time.strftime(date_format, time.localtime(timestamp)),
|
||||
"name" : name,
|
||||
"url" : f"entries/{name}.html"
|
||||
})(".".join(p.split(".")[:-1]))
|
||||
)(os.stat(path).st_ctime)
|
||||
)(open(path, "r").read())
|
||||
)(os.path.join(source, p)) for p in os.listdir(source)
|
||||
]
|
||||
|
||||
def formatEntry(content, page):
|
||||
return content.replace("%date%", page["date"])\
|
||||
.replace("%name%", page["name"])\
|
||||
.replace("%time%", str(page["timestamp"]))\
|
||||
.replace("%source%", site_index + page["source_file"])\
|
||||
.replace("%url%", site_index + page["url"])
|
||||
|
||||
def make():
|
||||
|
||||
shutil.rmtree(dist)
|
||||
os.makedirs(os.path.join(dist, "entries"))
|
||||
shutil.copytree(source, os.path.join(dist, "src"))
|
||||
shutil.copytree(images, os.path.join(dist, "images"))
|
||||
|
||||
pages = listPages()
|
||||
|
||||
summary_templ = getTemplateHTML("summary.html")
|
||||
|
||||
summariesHTML = "\n".join(
|
||||
[
|
||||
formatEntry(summary_templ, page)
|
||||
.replace(
|
||||
"%content%",
|
||||
"\n".join(page["html"].split("\n")[:10])
|
||||
)
|
||||
|
||||
for page in pages
|
||||
]
|
||||
)
|
||||
|
||||
entry_templ = getTemplateHTML("page.html")
|
||||
|
||||
for page in pages:
|
||||
with open(os.path.join(dist, page["url"]), "w") as entry:
|
||||
entry.write(
|
||||
formatEntry(
|
||||
entry_templ,
|
||||
page
|
||||
)
|
||||
.replace("%content%", page["html"])
|
||||
)
|
||||
|
||||
|
||||
|
||||
index_templ = getTemplateHTML("index.html")
|
||||
|
||||
with open(os.path.join(dist, "index.html"), "w") as index:
|
||||
index.write(
|
||||
index_templ.replace("%entries%", summariesHTML)
|
||||
)
|
||||
|
||||
|
||||
make()
|
||||
|
||||
|
||||
|
7
const.py
Normal file
7
const.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
site_index = "www.example.com/"
|
||||
images = "images"
|
||||
date_format = "%a, %d %b %Y"
|
||||
source = "src"
|
||||
templates = "templates"
|
||||
dist = "dist"
|
||||
summary_max = 10
|
14
new.sh
Executable file
14
new.sh
Executable file
|
@ -0,0 +1,14 @@
|
|||
#!/bin/sh
|
||||
|
||||
EDITOR=nvim
|
||||
TEMPFILE=/tmp/blog_entry.md
|
||||
|
||||
$EDITOR $TEMPFILE
|
||||
|
||||
NAME=src/$(head -1 $TEMPFILE | cut -d" " -f2-).md
|
||||
|
||||
cp $TEMPFILE "$NAME"
|
||||
rm $TEMPFILE
|
||||
python build.py
|
||||
|
||||
./sync.sh
|
12
src/another blog entry.md
Normal file
12
src/another blog entry.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
# another blog entry
|
||||
|
||||
Another blog entry to test
|
||||
|
||||
wow
|
||||
thats pretty cool
|
||||
|
||||
- things
|
||||
- things and
|
||||
- most
|
||||
- importantly
|
||||
- things
|
3
src/test blog entry.md
Normal file
3
src/test blog entry.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Test Blog entry
|
||||
|
||||
this is a test blog entry for my blog
|
2
src/test.md
Normal file
2
src/test.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
# This is test markdown
|
||||
- a test markdown document
|
5
sync.sh
Executable file
5
sync.sh
Executable file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
###
|
||||
# your syncing script here
|
||||
###
|
13
templates/index.html
Normal file
13
templates/index.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>blog test</h1>
|
||||
<div class="entries">
|
||||
%entries%
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
10
templates/page.html
Normal file
10
templates/page.html
Normal file
|
@ -0,0 +1,10 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>%name%</title>
|
||||
</head>
|
||||
<body>
|
||||
%content%
|
||||
</body>
|
||||
</html>
|
7
templates/summary.html
Normal file
7
templates/summary.html
Normal file
|
@ -0,0 +1,7 @@
|
|||
<div>
|
||||
%content%
|
||||
|
||||
...
|
||||
<a href="%url%">more</a>
|
||||
<p>Date: %date%</p>
|
||||
</div>
|
Loading…
Reference in a new issue