diff --git a/app/routes/guides.py b/app/routes/guides.py index 515d7ab..56097d3 100644 --- a/app/routes/guides.py +++ b/app/routes/guides.py @@ -1,11 +1,109 @@ -from flask import Blueprint, render_template +from flask import Blueprint, render_template, render_template_string, current_app, abort +from pathlib import Path +import re bp = Blueprint('guides', __name__, url_prefix='/guides/') +def parse_guide_title(content: str): + lines = content.strip().split('\n', 1) + fline = lines[0].strip() + if fline.startswith('#'): + title = fline[2:].strip() + content = lines[1] if len(lines) > 1 else '' + return title, content.strip() + + return None, content.strip() + + +def get_guides_by_category(): + guides_dir = Path(current_app.root_path) / 'templates' / 'guides' + categories = {} + + for item in guides_dir.iterdir(): + if item.is_dir() and not item.name.startswith('_'): + category = item.name + categories[category] = [] + for guide_file in sorted(item.glob('*.html')): + if guide_file.name.startswith('_'): + continue + + m = re.match(r'(\d+)-(.+)\.html', guide_file.name) + if not m: + continue + + sort_num = int(m.group(1)) + slug = m.group(2) + + try: + with open(guide_file, 'r') as f: + content = f.read() + + title, template = parse_guide_title(content) + if not title: + title = slug.replace('-', ' ').title() + + categories[category].append(({ + 'sort': sort_num, + 'slug': slug, + 'filename': guide_file.name, + 'title': title, + 'path': f'{category}/{guide_file.name}', + 'url': f'/guides/{category}/{slug}', + 'template': template, + })) + except Exception as e: + current_app.logger.warning(f'failed to read {guide_file}: {e}') + continue + + categories[category].sort(key=lambda x: x['sort']) + + return categories + + @bp.get('/babycode') def babycode(): - return render_template('guides/babycode.html') + # print(get_guides_by_category()) + return '
{{ config.SITE_NAME }} is powered by Pyrom, a home-grown forum software for the indie web. This guide will help you get started, from creating an account to understanding how discussions are organized.
+Most interactive features on {{ config.SITE_NAME }} such as creating threads or posting replies require a user account. While browsing is open to all, you must be signed in to participate.
+ {% if config.DISABLE_SIGNUP %} +{{ config.SITE_NAME }} uses an invite-only sign-up system. You cannot sign up directly. Instead, {% if config.USERS_CAN_INVITE %}an existing user{% elif config.MODS_CAN_INVITE %}a moderator{% endif %} can generate an invite link containing an invite key. Using that link will take you to the sign up page.
+ {% else %} +You can create an account on the sign-up page. After you create your account, a moderator will need to manually approve your account before you can post. This may take some time.
+ {% endif %} +To create an account, you will need to provide:
+Once your account is {% if not config.DISABLE_SIGNUP %}confirmed and{% endif %} active, you will have full access to create threads, post replies, and use other features.
+The front page of {{ config.SITE_NAME }} is an overview of topics that you can create threads in. A topic is a broad category created by moderators to organize discussions.
+Topics usually have a description that is shown under its name. Use it as guidance for where to post a thread. The order topics show up in is chosen by moderators.
+A topic may be locked by a moderator. This will prevent threads from being created or moved into it by non-moderators. These topics are usually used for forum-wide information, but it is of course up to the moderators.
+By default, threads in a topic are sorted by activity, but this can be changed in your user settings.
+Threads are where discussion happens. A thread is started by a user with a name and an initial post, and other users may add their own posts to it (known as replying to the thread).
+When drafting a thread, you have to choose which topic to post it under. Be sure to follow the posting rules. If you created a thread under the wrong topic, you may move it when viewing replies. Moderators have the option to move any thread.
+A thread may be locked by the original poster (OP) or a moderator. When a thread is locked, nobody except moderators can reply to it.
+A thread may also be stickied by a moderator. Stickied threads show above all other threads in the topic it's under. If a thread is stickied, it is likely important.
+You can subscribe to any thread. When subscribed, you will receive an overview of posts you missed for that thread in your inbox.
+You can
+Posts are the individual messages that make up a thread. The first post starts the thread, and every subsequent message is a post in reply.
+A post is split up into five sections:
+You may edit or delete your posts after creating them. Edited posts will show when they were edited instead of when they were posted.
+You can quote another user's post by pressing the button on that post. This will copy the contents of it into the reply box and mention the user.
+Posts are written in a markup language called Babycode. More information on it can be found in a separate guide.
+Each user on {{ config.SITE_NAME }} has a profile.
+A user's profile shows:
+You can access your settings by following the "Settings" link in the top navigation bar or from the button in your profile.
+The settings page lets you set your avatar, change your personalization options, and change your password.
+When you upload an avatar, keep in mind that it will be cropped to a square and resized to fit 256 by 256 pixels. It's best to upload an image that is already square. Avatars must be no more than 1 MB in size. You can also clear your avatar, resetting it to the default one.
+To change your avatar, first press the button and select a file from your device, then press the button to upload it.
+The personalization section of the settings lets you change the following settings:
+You can change your password by typing it in the "New password" field and again in the "Confirm new password" field, then pressing the button. The passwords in the two fields must match.
+If you no longer wish to participate in {{ config.SITE_NAME }}, you may delete your account. To do so, press the button in your settings, which will take you to a confirmation page.
+Deleting your account is an irreversible action. Once you delete your account, you will not be able to log back in to it.
+Deleting your account does not delete your threads and posts. They will be kept intact to preserve history. They will be altered to show up as if a system user authored them.
+If you want your posts and threads to be deleted as well, you may either delete them yourself or contact the administrators for help.
+If you're sure you want to delete your account, you will need to type your password on the confirmation page before pressing the button.
+You can subscribe to any thread. When subscribed, you will receive an overview of posts you missed for that thread in your inbox.
+Additionally, when browsing a topic, threads you've subscribed to will show the number of posts you haven't read in it next to the thread's name.
+You can access your Inbox by following the "Inbox" link in the top navigation bar.
+The Inbox is split into two parts:
+Your inbox is updated automatically when you browse a subscribed thread. Once you've seen the posts you missed, they will disappear from your Inbox.
+You can bookmark whole threads or individual posts to save them for later reading. Bookmarks are split into collections.
+Each post or thread you bookmark (collectively bookmarks) can only belong to one collection.
+Each bookmark can have a short memo that you can add to it, for example to help you remember why you saved it.
+Bookmarks are organized into collections. There is always at least one collection you have access to, called "Bookmarks" by default.
+You can add any number of collections by pressing the button on the your bookmarks page.
+On the "Manage bookmark collections" page, you can add, delete, rename, and reorder your collections.
+To add a new collection, press the button. A new item will be added.
+You can name any collection by using the input box.
+You can reorder collections by dragging and dropping it above or below others. The default collection is always at the top and can not be moved.
+You can delete a collection by pressing the button on that collection. Deleting a collection will remove all bookmarks from it. If you delete a collection by accident, simply refresh the page. Your changes are not saved until you press the button.
+Both will bring up a popup with your bookmark collections. You can select the collection to save the bookmark into by pressing its name and add an optional memo. To save the bookmark, press the button. Each bookmark can only belong to one collection.
+If the post or thread is already bookmarked, the name of the collection will be highlighed and the box to its name will be filled. If you wish to remove the bookmark, press the name of the collection it's in and press the button.
+You can access your bookmarks by following the "Bookmarks" link in the top navigation bar.
+On the Bookmarks page, each collection will show up as a collapsible section. If a collection is empty, it will be collapsed.
+If a collection has any bookmarks, it will have two collapsibe sections nested inside it: one for threads and one for posts.
+Bookmarked threads are shown as a table with their title, the memo, and a button. Pressing this button will show the same popup, letting you move or remove the bookmark.
+Bookmarked posts are shown in the same way they're shown in a thread. The memo will be shown before the post's time stamp. To the right of the post is the same button.
+If you made changes to bookmarked threads or posts on this page, you will have to refresh to save those changes.
+You may be familiar with BBCode, a loosely related family of markup languages popular on forums. Babycode is another, simplified, dialect of those languages. It is a way of formatting text by enclosing parts of it in special tags.
A tag is a short name enclosed in square brackets. Tags can be opening tags, like [b] or closing tags, like [/b]. Anything inserted between matching opening and closing tags is known as the tag's content.
Some tags can provide more specific instructions using an attribute. An attribute is added to the opening tag with an equals sign (=). This allows you to specify details like a particular color or a link's address.
Babycode is used in posts, user signatures, and MOTDs.
[@] tag allows you to use the @ symbol without it being turned into a mention.