docs: Add new doc pages (#1545)

* docs: Add new doc pages

docs: Add new updates rollbacks and rebase section

docs: Add Bazzite Resources post

docs: Add reporting bugs post

docs: Add secure boot post

docs: Add installation troubleshoot guide post

docs: Add dual boot setup guide post

docs: Add common gaming issues post

docs: Add managing and modding games post

docs: Add hardware compatibility for gaming post

* docs: Remove emojies from page names

* docs: Simplify image fetching logic

This fixes #1547 missing images.
Credit to @wolfyreload for the tip about 'uploads/short-url'
This commit is contained in:
Zeglius 2024-08-26 21:59:19 +02:00 committed by GitHub
parent 8137631e78
commit 3a28c6e905
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 66 additions and 119 deletions

View File

@ -0,0 +1 @@
<!-- cmdrun fetch_discourse_md.py "https://universal-blue.discourse.group/docs?topic=43" -->

View File

@ -0,0 +1 @@
<!-- cmdrun fetch_discourse_md.py "https://universal-blue.discourse.group/docs?topic=8" -->

View File

@ -0,0 +1 @@
<!-- cmdrun fetch_discourse_md.py "https://universal-blue.discourse.group/docs?topic=2658" -->

View File

@ -0,0 +1 @@
<!-- cmdrun fetch_discourse_md.py "https://universal-blue.discourse.group/docs?topic=35" -->

View File

@ -0,0 +1 @@
<!-- cmdrun fetch_discourse_md.py "https://universal-blue.discourse.group/docs?topic=2657" -->

View File

@ -0,0 +1 @@
<!-- cmdrun fetch_discourse_md.py "htthttps://universal-blue.discourse.group/docs?topic=2743" -->

View File

@ -0,0 +1 @@
<!-- cmdrun fetch_discourse_md.py "https://universal-blue.discourse.group/docs?topic=2742" -->

View File

@ -0,0 +1 @@
<!-- cmdrun fetch_discourse_md.py "https://universal-blue.discourse.group/docs?topic=2495" -->

View File

@ -0,0 +1 @@
<!-- cmdrun fetch_discourse_md.py "https://universal-blue.discourse.group/docs?topic=3402" -->

View File

@ -0,0 +1 @@
<!-- cmdrun fetch_discourse_md.py "https://universal-blue.discourse.group/docs?topic=2647" -->

View File

@ -0,0 +1 @@
<!-- cmdrun fetch_discourse_md.py "https://universal-blue.discourse.group/docs?topic=2646" -->

View File

@ -0,0 +1 @@
<!-- cmdrun fetch_discourse_md.py "https://universal-blue.discourse.group/docs?topic=2644" -->

View File

@ -0,0 +1 @@
<!-- cmdrun fetch_discourse_md.py "https://universal-blue.discourse.group/docs?topic=2637" -->

View File

@ -4,29 +4,36 @@
</div>
# General
# Table of Contents
- [📜 Bazzite's README](Bazzite_README.md)
- [❓️ FAQ](General/FAQ.md)
- [📖 Installation Guide](General/Installation_Guide/index.md)
- [Bazzite's README](Bazzite_README.md)
- [Bazzite Resources](Bazzite_resources.md)
- [FAQ](General/FAQ.md)
- [Installation Guide](General/Installation_Guide/index.md)
- [🖥️ Installing Bazzite for Desktop/Laptop Hardware](General/Installation_Guide/Installing_Bazzite_for_Desktop_or_Laptop_Hardware.md)
- [⚙️ Installing Bazzite for Framework Laptop 16](General/Installation_Guide/Installing_Bazzite_for_Framework_Laptop_16.md)
- [💻️ Installing Bazzite for Framework Laptop 13 (AMD/Intel GPU)](General/Installation_Guide/Installing_Bazzite_Framework_Laptop_13.md)
- [🎮️ Installing Bazzite for Home Theater PC (HTPC) Setups](General/Installation_Guide/Installing_Bazzite_for_HTPC_Setups.md)\*
- [🚂 Installing Bazzite on the Steam Deck](General/Installation_Guide/Installing_Bazzite_for_Steam_Deck.md)\*
- [📟️ Installing Bazzite on Handheld PCs](General/Installation_Guide/Installing_Bazzite_for_Handheld_PCs.md)\*
- [Installing Bazzite for Desktop/Laptop Hardware](General/Installation_Guide/Installing_Bazzite_for_Desktop_or_Laptop_Hardware.md)
- [Installing Bazzite for Framework Laptop 16](General/Installation_Guide/Installing_Bazzite_for_Framework_Laptop_16.md)
- [Installing Bazzite for Framework Laptop 13 (AMD/Intel GPU)](General/Installation_Guide/Installing_Bazzite_Framework_Laptop_13.md)
- [Installing Bazzite for Home Theater PC (HTPC) Setups](General/Installation_Guide/Installing_Bazzite_for_HTPC_Setups.md)\*
- [Installing Bazzite on the Steam Deck](General/Installation_Guide/Installing_Bazzite_for_Steam_Deck.md)\*
- [Installing Bazzite on Handheld PCs](General/Installation_Guide/Installing_Bazzite_for_Handheld_PCs.md)\*
- [Installation Troubleshoot Guide](General/Installation_Guide/troubleshoot_guide.md)
- [Secure Boot Instructions](General/Installation_Guide/secure_boot.md)
- [Dual Boot Preliminary Setup and Post-Setup Guide](General/Installation_Guide/dual_boot_setup_guide.md)
\* _Indicates that Steam Gaming Mode is intended for this device and ships with the ISO._
- [📝 Desktop Environment Tweaks](General/Desktop_Environment_Tweaks.md)
- [🤝 Contributing to Bazzite](General/Contributing_to_Bazzite.md)
- [🎲 Gaming](Gaming/index.md)
- [Gaming](Gaming/index.md)
- [Game Launchers](Gaming/Game_Launchers.md)
- [Managing & Modding Games](Gaming/Managing_and_modding_games.md)
- [Common Gaming Issues](Gaming/Common_gaming_issues.md)
- [Hardware Compatibility for Gaming](Gaming/Common_gaming_issues.md)
- [Desktop Environment Tweaks](General/Desktop_Environment_Tweaks.md)
- [Reporting Bugs](General/reporting_bugs.md)
# Steam Gaming Mode / Handheld & HTPC Hardware
- [📺️ Steam Gaming Mode Overview](Handheld_and_HTPC_edition/Steam_Gaming_Mode/index.md)
- [Steam Gaming Mode Overview](Handheld_and_HTPC_edition/Steam_Gaming_Mode/index.md)
- [Change Physical Keyboard Layout for Steam Gaming Mode](Handheld_and_HTPC_edition/Change_Physical_Keyboard_Layout_for_Steam_Gaming_Mode.md)
- [Handheld Wiki](Handheld_and_HTPC_edition/Handheld_Wiki/index.md)
- [Steam Deck](Handheld_and_HTPC_edition/Handheld_Wiki/Steam_Deck.md)
@ -46,9 +53,13 @@
- [Distrobox](Installing_and_Managing_Software/Distrobox.md)
- [Appimage](Installing_and_Managing_Software/AppImage.md)
- [rpm-ostree](Installing_and_Managing_Software/rpm-ostree.md)
- [Waydroid Setup Guide](Installing_and_Managing_Software/Waydroid_Setup_Guide.md)
- [Tutorials for Installing Other Software](Installing_and_Managing_Software/index.md)
- [Updates, Rollbacks, & Rebasing](Installing_and_Managing_Software/Updates_Rollbacks_&_Rebasing.md)
- [Updates, Rollbacks, & Rebasing](Installing_and_Managing_Software/Updates_Rollbacks_&_Rebasing/index.md)
- [Updating Guide](Installing_and_Managing_Software/Updates_Rollbacks_&_Rebasing/updating_guide.md)
- [Rolling Back System Updates](Installing_and_Managing_Software/Updates_Rollbacks_&_Rebasing/rolling_back_system_updates.md)
- [Rebase Guide](Installing_and_Managing_Software/Updates_Rollbacks_&_Rebasing/rebase_guide.md)
- [Bazzite Rollback Helper](Installing_and_Managing_Software/Updates_Rollbacks_&_Rebasing/bazzite_rollback_helper.md)
- [Waydroid Setup Guide](Installing_and_Managing_Software/Waydroid_Setup_Guide.md)
# Advanced

View File

@ -85,7 +85,6 @@ How does this script work:
from argparse import ArgumentParser
from copy import copy
from datetime import datetime, UTC
import fcntl
import html
@ -95,7 +94,7 @@ import re
from string import Template
from sys import stdout, stderr
from time import sleep
from typing import NamedTuple
from typing import NamedTuple, cast
import requests
@ -146,30 +145,10 @@ class DiscourseProcessor:
imgs_urls = re.compile(
r"<img\ssrc=\"(?P<image_cdn_url>https://(?:[a-zA-Z0-9./_-]+)).*data-base62-sha1=\"(?P<sha1>[a-zA-Z0-9]+)\".*\">"
)
hashed_images_urls = re.compile(r"upload://[a-zA-Z0-9]{27}\.(?:jpe?g|png|svg)")
@staticmethod
def is_valid_doc_topic_url(url: str) -> bool:
"""Check if the passed discourse topic url is valid doc
Args:
url (str)
Returns:
bool
"""
return (
# re.match(r"https\:\/\/universal-blue\.discourse\.group/docs\?topic=\d+", url)
re.match(
re.escape(_BASE_URL) + r"/docs\?topic=\d+",
url,
)
is not None
)
hashed_images_urls = re.compile(r"upload://([a-zA-Z0-9]{27})")
@classmethod
def transform_to_url_batch(cls, url: str) -> UrlBatch | None:
def transform_to_url_batch(cls, url: str) -> UrlBatch:
"""Input a discourse url topic and return a batch of urls such as `/raw/{id}` and `/t/{id}.json`
Args:
@ -177,11 +156,8 @@ class DiscourseProcessor:
"""
res = None
if not cls.is_valid_doc_topic_url(url):
raise TypeError("Url is not valid")
# Get topic id
id = re.search(re.escape(_BASE_URL) + r"/docs\?topic=(\d+)", url)
id = re.search(rf"{re.escape(_BASE_URL)}/docs\?topic=(\d+)", url)
if id is None:
raise Exception("id was not found")
id = int(id.group(1))
@ -194,23 +170,6 @@ class DiscourseProcessor:
return res
@classmethod
def get_page_from_json(cls, batch: UrlBatch) -> HTMLPage:
"""Get webpage contents from an url link
This includes images urls from discourse cdn
Args:
batch (UrlBatch)
"""
json_content = (res := cls.fetch(batch.json_url)).json()
debug(f"{res.url} res.status = {res.status_code}")
if res.status_code != 200:
raise Exception(res.reason)
# json_content = json.loads(json_content)
return json_content["post_stream"]["posts"][0]["cooked"]
@classmethod
def fetch(cls, url: str) -> requests.Response:
tries = 2
@ -228,41 +187,9 @@ class DiscourseProcessor:
return res
@classmethod
def get_markdown_from_raw(cls, batch: UrlBatch) -> Markdown:
"""Get markdown from page
This is recommended for extracting text transcriptions
Args:
batch (UrlBatch): _description_
Returns:
str:
"""
return requests.get(batch.raw_url).text
@classmethod
def get_images_url_assocs_from_page(cls, page: HTMLPage) -> ImageUrlAssocs:
result: list[tuple] = []
for match in re.finditer(DiscourseProcessor.Patterns.imgs_urls, page):
debug(match.__str__())
(sha1, image_cdn_url) = match.group("sha1", "image_cdn_url")
result.append((sha1, image_cdn_url))
return result
@classmethod
def replace_images_urls_in_markdown(
cls, page: Markdown, assocs: ImageUrlAssocs
) -> Markdown:
result = page
for assoc in assocs:
result = result.replace(
f"upload://{assoc[0]}",
os.path.splitext(assoc[1])[0],
)
return result
@staticmethod
def get_markdown_from_url(url: str):
return requests.get(url).text
@staticmethod
def add_metadata_to_markdown(md: Markdown, url_discourse: str) -> Markdown:
@ -296,12 +223,18 @@ class DiscourseProcessor:
return "\n".join(md_split)
def simple_replace_match(match: re.Match) -> str:
hash = match.group(1)
if hash:
return f"{_BASE_URL}/uploads/short-url/{hash}"
return ""
def main():
argparser = ArgumentParser()
argparser.add_argument(
"url",
type=str,
nargs=1, # Change this to `+` if you wish to process multiple urls
help="discourse urls to be processed",
)
argparser.add_argument(
@ -317,30 +250,20 @@ def main():
global _is_debug
_is_debug = os.getenv("DEBUG") == "1" or args.debug
urls = args.url
urls = cast(str, DiscourseProcessor.transform_to_url_batch(args.url).raw_url)
urls_batches_list: list[UrlBatch] = []
for url in urls:
batch = DiscourseProcessor.transform_to_url_batch(url)
if batch is None:
continue
urls_batches_list.append(batch)
for batch in urls_batches_list:
image_urls_assocs = DiscourseProcessor.get_images_url_assocs_from_page(
DiscourseProcessor.get_page_from_json(batch)
)
result = DiscourseProcessor.replace_images_urls_in_markdown(
page=DiscourseProcessor.get_markdown_from_raw(batch),
assocs=image_urls_assocs,
result = DiscourseProcessor.get_markdown_from_url(urls)
result = re.sub(
DiscourseProcessor.Patterns.hashed_images_urls,
simple_replace_match,
result,
)
# Remove comments
result = DiscourseProcessor.Patterns.post_sep_markdown.split(result, 1)[0].rstrip()
# Add metadata
result = DiscourseProcessor.add_metadata_to_markdown(result, batch.source_url)
result = DiscourseProcessor.add_metadata_to_markdown(result, urls)
print(result, file=stdout)