Made it look a bit nicer and added a cascading menu thing

This commit is contained in:
2025-10-17 17:48:37 +01:00
parent 5d51b7ecfa
commit c07c24e86f
13 changed files with 114 additions and 29 deletions

1
.gitignore vendored
View File

@@ -1,5 +1,4 @@
wiki-pages/* wiki-pages/*
webroot/*
venv/ venv/
__pycache__/ __pycache__/
data/* data/*

View File

@@ -3,3 +3,7 @@ port=8080
domain='example.com' domain='example.com'
debug=True debug=True
allow_signup=False allow_signup=False
locale='en'
name='This Awesome Wiki!'
description='This is about all things awesome'

View File

@@ -1,13 +1,24 @@
import config import config
import json import json
def get_data(data_type, key, value): def get_data(data_type, key='', value=''):
if data_type == 'users': json_string = ''
users_json_string = open('data/users.json', 'r').read() match data_type:
json_data = json.loads(users_json_string) case 'users':
json_string = open('data/users.json','r').read()
case 'menu':
json_string = open('data/menu.json','r').read()
case _:
json_string = ''
print('Error, invalid data type (data_management.get_data)')
json_data = json.loads(json_string)
if key != '':
for json_object in json_data: for json_object in json_data:
if json_object[key] == value: if json_object[key] == value:
return json_object return json_object
else:
return json_data
return -1 return -1

View File

@@ -3,3 +3,24 @@ import hashlib
def sha512_hash(Password): def sha512_hash(Password):
HashedPassword = hashlib.sha512(Password.encode('utf-8')).hexdigest() HashedPassword = hashlib.sha512(Password.encode('utf-8')).hexdigest()
return HashedPassword return HashedPassword
def dropdown_menu(object_input):
html = ''
def loop(x, count):
html = ''
for key,value in x.items():
print(' ' * count * 5, key)
if type(value) == dict:
html += f'<details style="left: {count * 5}px; position: relative">'
html += f'<summary>{key}</summary>'
html += loop(x[key], count+1)
html += f'</details>'
else:
html += f'<a href="/wiki/{value}" style="left: {count * 5}px; position: relative">{key}</a><br/>'
return html
count = 0
html += loop(object_input, count)
print(html)
return html

36
main.py
View File

@@ -11,19 +11,23 @@ app = Flask(__name__)
@app.route('/') @app.route('/')
def index(): def index():
pages = os.listdir('./wiki-pages') menu = data_management.get_data('menu')
pages_string = '' return render_template(
for page in pages: 'index.html',
if page[-3:] == '.md': config=config,
pages_string += f'<a href="/wiki/{page[:-3]}">{page[:-3]}</a><br/>' menu=menu,
return render_template('index.html', pages=pages_string) functions=functions
)
@app.route('/wiki/<page>') @app.route('/wiki/<page>')
def wiki_page(page): def wiki_page(page):
if os.path.isfile(f'./wiki-pages/{page}.md'): if os.path.isfile(f'./wiki-pages/{page}.md'):
file_contents = md.render(open(f'./wiki-pages/{page}.md', 'r').read()) file_contents = md.render(open(f'./wiki-pages/{page}.md', 'r').read())
menu = data_management.get_data('menu')
return render_template( return render_template(
'wiki-page.html', 'wiki-page.html',
functions=functions,
menu=menu,
content=file_contents, content=file_contents,
page_title=page page_title=page
) )
@@ -32,19 +36,25 @@ def wiki_page(page):
@app.route('/create_page') @app.route('/create_page')
def create_page(): def create_page():
return render_template('forms/create_page.html') menu = data_management.get_data('menu')
@app.route('/submit_create_page', methods=['POST']) return render_template(
def submit_create_page(): 'forms/create_page.html',
page_name = request.form['page_name'] functions=functions,
return redirect(f'/edit/{page_name}', 302) menu=menu,
config=config
)
@app.route('/edit/<page>') @app.route('/edit/<page>')
def edit_page(page): def edit_page(page):
menu = data_management.get_data('menu')
if os.path.isfile(f'./wiki-pages/{page}.md'): if os.path.isfile(f'./wiki-pages/{page}.md'):
file_contents = open(f'./wiki-pages/{page}.md', 'r').read() file_contents = open(f'./wiki-pages/{page}.md', 'r').read()
return render_template( return render_template(
'forms/edit-page.html', 'forms/edit-page.html',
content=file_contents, content=file_contents,
functions=functions,
menu=menu,
page_title=page page_title=page
) )
else: else:
@@ -55,6 +65,10 @@ def edit_page(page):
) )
# Forms # Forms
@app.route('/submit_create_page', methods=['POST'])
def submit_create_page():
page_name = request.form['page_name']
return redirect(f'/edit/{page_name}', 302)
@app.route('/submit-edit', methods=['POST']) @app.route('/submit-edit', methods=['POST'])
def submit_edit_page(): def submit_edit_page():
page = request.form['page'] page = request.form['page']

15
static/custom.css Normal file
View File

@@ -0,0 +1,15 @@
* {
font: Sans-Serif;
}
body {
background: #fbf1d7;
}
a {
background: #83c5b8;
text-decoration: none;
}
a:hover {
background: #fe8019;
text-decoration: underline;
}

2
static/robots.txt Normal file
View File

@@ -0,0 +1,2 @@
User-Agent: *
Disallow: /

View File

@@ -1,3 +1,8 @@
<!DOCTYPE html>
</html>
<head>
{% include 'partials/head.html' %}
</head>
<body> <body>
<header> <header>
{% include 'partials/site-wide-header.html' %} {% include 'partials/site-wide-header.html' %}

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head>
{% include 'partials/head.html' %}
</head>
<body> <body>
<header> <header>
{% include 'partials/site-wide-header.html' %} {% include 'partials/site-wide-header.html' %}

View File

@@ -1,13 +1,18 @@
<!DOCTYPE html>
<html> <html>
<body> <head>
<header> {% include 'partials/head.html' %}
{% include 'partials/site-wide-header.html' %} </head>
</header> <body>
Welcome to My Wiki Site!<br/> <header>
Pages:<br/> {% include 'partials/site-wide-header.html' %}
{{pages|safe}} </header>
<footer> <span>
{% include 'partials/site-wide-footer.html' %} <h1>{{ config.name }}</h1>
</footer> {{config.description}}
</body> </span>
<footer>
{% include 'partials/site-wide-footer.html' %}
</footer>
</body>
</html> </html>

View File

@@ -0,0 +1,2 @@
<link href="/static/custom.css" rel="stylesheet">
<meta charset='UTF-8'>

View File

@@ -1,4 +1,4 @@
<a href='/'>Home Page</a> <a href='/'>Home Page</a>
/ <a href='/create_page'>Create Page</a>
<a href='/create_page'>Create New Page</a> {{functions.dropdown_menu(menu)|safe}}
<hr/> <hr/>

View File

@@ -1,4 +1,8 @@
<!DOCTYPE html>
<html> <html>
<head>
{% include 'partials/head.html' %}
</head>
<body> <body>
<header> <header>
{% include 'partials/site-wide-header.html' %} {% include 'partials/site-wide-header.html' %}