test static gen

thumb
km0 2 years ago
parent c19071f117
commit 23dacbcbc2

@ -46,6 +46,32 @@ def get_md_contents(filename, directory='./contents'):
return metadata, html_content
def render_home():
with open('render.html', 'r+w') as f:
# get the basic info of the website from the /contents/home.md file
meta, content = get_md_contents("home.md")
projects_list = []
for project in list_folders("./projects"):
project_info = get_md_contents("documentation.md",
f"./{projects}/{project}")[0]
project_date = datetime.strptime(project_info['date'], '%d/%m/%Y')
project_info['date'] = datetime.strftime(project_date, '%d %b, %y')
project_info['categories'].sort()
project_info['slug'] = project
projects_list.append(project_info)
projects_list.sort(reverse=True, key=lambda project: datetime.strptime(
project['date'], '%d %b, %y'))
# get the list of the projects, the functions, and the corpora
home = {
**meta,
"content": content,
"projects": projects_list
}
f.write(render_template("home.html", **home))
# FLASK APP
base_url = "~kamo"
projects = 'projects'
@ -67,30 +93,7 @@ def set_base_url():
# Homepage
@app.route(f"/{base_url}/")
def home_page():
# get the basic info of the website from the /contents/home.md file
meta, content = get_md_contents("home.md")
projects_list = []
for project in list_folders("./projects"):
project_info = get_md_contents("documentation.md",
f"./{projects}/{project}")[0]
project_date = datetime.strptime(project_info['date'], '%d/%m/%Y')
project_info['date'] = datetime.strftime(project_date, '%d %b, %y')
project_info['categories'].sort()
project_info['slug'] = project
projects_list.append(project_info)
projects_list.sort(reverse=True, key=lambda project: datetime.strptime(
project['date'], '%d %b, %y'))
# get the list of the projects, the functions, and the corpora
home = {
**meta,
"content": content,
"projects": projects_list
}
return render_template("home.html", **home)
return send_from_directory(f'{app.root_path}/render.html')
# For generic pages we can include a common template and change only the contents
@ -123,7 +126,12 @@ def sendStaticFiles(project, filename):
def pull():
if request.method == 'POST':
subprocess.call(['sh', '/home/kamo/public_html/update.sh'])
print(request.form['payload'])
with open('log.txt', 'a') as f:
f.write(request.form['payload'])
render_home()
return 'Updated'
return 'GET method not supported'

Loading…
Cancel
Save