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/*
webroot/*
venv/
__pycache__/
data/*

View File

@@ -3,3 +3,7 @@ port=8080
domain='example.com'
debug=True
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 json
def get_data(data_type, key, value):
if data_type == 'users':
users_json_string = open('data/users.json', 'r').read()
json_data = json.loads(users_json_string)
def get_data(data_type, key='', value=''):
json_string = ''
match data_type:
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:
if json_object[key] == value:
return json_object
else:
return json_data
return -1

View File

@@ -3,3 +3,24 @@ import hashlib
def sha512_hash(Password):
HashedPassword = hashlib.sha512(Password.encode('utf-8')).hexdigest()
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('/')
def index():
pages = os.listdir('./wiki-pages')
pages_string = ''
for page in pages:
if page[-3:] == '.md':
pages_string += f'<a href="/wiki/{page[:-3]}">{page[:-3]}</a><br/>'
return render_template('index.html', pages=pages_string)
menu = data_management.get_data('menu')
return render_template(
'index.html',
config=config,
menu=menu,
functions=functions
)
@app.route('/wiki/<page>')
def wiki_page(page):
if os.path.isfile(f'./wiki-pages/{page}.md'):
file_contents = md.render(open(f'./wiki-pages/{page}.md', 'r').read())
menu = data_management.get_data('menu')
return render_template(
'wiki-page.html',
functions=functions,
menu=menu,
content=file_contents,
page_title=page
)
@@ -32,19 +36,25 @@ def wiki_page(page):
@app.route('/create_page')
def create_page():
return render_template('forms/create_page.html')
@app.route('/submit_create_page', methods=['POST'])
def submit_create_page():
page_name = request.form['page_name']
return redirect(f'/edit/{page_name}', 302)
menu = data_management.get_data('menu')
return render_template(
'forms/create_page.html',
functions=functions,
menu=menu,
config=config
)
@app.route('/edit/<page>')
def edit_page(page):
menu = data_management.get_data('menu')
if os.path.isfile(f'./wiki-pages/{page}.md'):
file_contents = open(f'./wiki-pages/{page}.md', 'r').read()
return render_template(
'forms/edit-page.html',
content=file_contents,
functions=functions,
menu=menu,
page_title=page
)
else:
@@ -55,6 +65,10 @@ def edit_page(page):
)
# 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'])
def submit_edit_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>
<header>
{% include 'partials/site-wide-header.html' %}

View File

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

View File

@@ -1,13 +1,18 @@
<!DOCTYPE html>
<html>
<body>
<header>
{% include 'partials/site-wide-header.html' %}
</header>
Welcome to My Wiki Site!<br/>
Pages:<br/>
{{pages|safe}}
<footer>
{% include 'partials/site-wide-footer.html' %}
</footer>
</body>
<head>
{% include 'partials/head.html' %}
</head>
<body>
<header>
{% include 'partials/site-wide-header.html' %}
</header>
<span>
<h1>{{ config.name }}</h1>
{{config.description}}
</span>
<footer>
{% include 'partials/site-wide-footer.html' %}
</footer>
</body>
</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='/create_page'>Create New Page</a>
<a href='/create_page'>Create Page</a>
{{functions.dropdown_menu(menu)|safe}}
<hr/>

View File

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