From c07c24e86f2e5bcb546d1f06cc948fae4282eb80 Mon Sep 17 00:00:00 2001 From: deadvey Date: Fri, 17 Oct 2025 17:48:37 +0100 Subject: [PATCH] Made it look a bit nicer and added a cascading menu thing --- .gitignore | 1 - config.py | 4 +++ data_management.py | 19 ++++++++++--- functions.py | 21 ++++++++++++++ main.py | 36 ++++++++++++++++-------- static/custom.css | 15 ++++++++++ static/robots.txt | 2 ++ templates/forms/create_page.html | 5 ++++ templates/forms/edit-page.html | 3 ++ templates/index.html | 27 ++++++++++-------- templates/partials/head.html | 2 ++ templates/partials/site-wide-header.html | 4 +-- templates/wiki-page.html | 4 +++ 13 files changed, 114 insertions(+), 29 deletions(-) create mode 100644 static/custom.css create mode 100644 static/robots.txt create mode 100644 templates/partials/head.html diff --git a/.gitignore b/.gitignore index 2149892..643c2da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ wiki-pages/* -webroot/* venv/ __pycache__/ data/* diff --git a/config.py b/config.py index cdc9672..1056ee7 100644 --- a/config.py +++ b/config.py @@ -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' diff --git a/data_management.py b/data_management.py index 8b722d3..00543ea 100644 --- a/data_management.py +++ b/data_management.py @@ -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 diff --git a/functions.py b/functions.py index d33bcbe..558f5fb 100644 --- a/functions.py +++ b/functions.py @@ -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'
' + html += f'{key}' + html += loop(x[key], count+1) + html += f'
' + else: + html += f'{key}
' + return html + + count = 0 + html += loop(object_input, count) + print(html) + return html diff --git a/main.py b/main.py index 6776a63..3628fb7 100644 --- a/main.py +++ b/main.py @@ -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'{page[:-3]}
' - 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/') 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/') 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'] diff --git a/static/custom.css b/static/custom.css new file mode 100644 index 0000000..86420a3 --- /dev/null +++ b/static/custom.css @@ -0,0 +1,15 @@ +* { + font: Sans-Serif; +} +body { + background: #fbf1d7; +} +a { + background: #83c5b8; + text-decoration: none; +} +a:hover { + background: #fe8019; + text-decoration: underline; +} + diff --git a/static/robots.txt b/static/robots.txt new file mode 100644 index 0000000..c6742d8 --- /dev/null +++ b/static/robots.txt @@ -0,0 +1,2 @@ +User-Agent: * +Disallow: / diff --git a/templates/forms/create_page.html b/templates/forms/create_page.html index faa242d..f7b8f6e 100644 --- a/templates/forms/create_page.html +++ b/templates/forms/create_page.html @@ -1,3 +1,8 @@ + + + + {% include 'partials/head.html' %} +
{% include 'partials/site-wide-header.html' %} diff --git a/templates/forms/edit-page.html b/templates/forms/edit-page.html index 2575065..3e88b4d 100644 --- a/templates/forms/edit-page.html +++ b/templates/forms/edit-page.html @@ -1,5 +1,8 @@ + + {% include 'partials/head.html' %} +
{% include 'partials/site-wide-header.html' %} diff --git a/templates/index.html b/templates/index.html index aee0c67..22ef631 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,13 +1,18 @@ + - -
- {% include 'partials/site-wide-header.html' %} -
- Welcome to My Wiki Site!
- Pages:
- {{pages|safe}} -
- {% include 'partials/site-wide-footer.html' %} -
- + + {% include 'partials/head.html' %} + + +
+ {% include 'partials/site-wide-header.html' %} +
+ +

{{ config.name }}

+ {{config.description}} +
+
+ {% include 'partials/site-wide-footer.html' %} +
+ diff --git a/templates/partials/head.html b/templates/partials/head.html new file mode 100644 index 0000000..d858b10 --- /dev/null +++ b/templates/partials/head.html @@ -0,0 +1,2 @@ + + diff --git a/templates/partials/site-wide-header.html b/templates/partials/site-wide-header.html index c113c94..173199a 100644 --- a/templates/partials/site-wide-header.html +++ b/templates/partials/site-wide-header.html @@ -1,4 +1,4 @@ Home Page -/ -Create New Page +Create Page +{{functions.dropdown_menu(menu)|safe}}
diff --git a/templates/wiki-page.html b/templates/wiki-page.html index e5dc399..a4e439d 100644 --- a/templates/wiki-page.html +++ b/templates/wiki-page.html @@ -1,4 +1,8 @@ + + + {% include 'partials/head.html' %} +
{% include 'partials/site-wide-header.html' %}