feat: Add max width for Now page contents
All checks were successful
Build Docker / BuildImage (push) Successful in 54s
All checks were successful
Build Docker / BuildImage (push) Successful in 54s
This commit is contained in:
@@ -2,7 +2,7 @@ from flask import Blueprint, render_template, make_response, request, jsonify
|
|||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
from tools import getHandshakeScript, error_response, isCLI
|
from tools import getHandshakeScript, error_response, isCLI
|
||||||
from curl import get_header
|
from curl import get_header, MAX_WIDTH
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@@ -96,6 +96,21 @@ def render_curl(date=None):
|
|||||||
|
|
||||||
# Extract any <a> links in the paragraph
|
# Extract any <a> links in the paragraph
|
||||||
links = [a.get("href") for a in p.find_all("a", href=True)] # type: ignore
|
links = [a.get("href") for a in p.find_all("a", href=True)] # type: ignore
|
||||||
|
# Set max width for text wrapping
|
||||||
|
|
||||||
|
# Wrap text manually
|
||||||
|
wrapped_lines = []
|
||||||
|
for line in text.splitlines():
|
||||||
|
while len(line) > MAX_WIDTH:
|
||||||
|
# Find last space within max_width
|
||||||
|
split_at = line.rfind(' ', 0, MAX_WIDTH)
|
||||||
|
if split_at == -1:
|
||||||
|
split_at = MAX_WIDTH
|
||||||
|
wrapped_lines.append(line[:split_at].rstrip())
|
||||||
|
line = line[split_at:].lstrip()
|
||||||
|
wrapped_lines.append(line)
|
||||||
|
text = "\n".join(wrapped_lines)
|
||||||
|
|
||||||
if links:
|
if links:
|
||||||
text += "\nLinks: " + ", ".join(links) # type: ignore
|
text += "\nLinks: " + ", ".join(links) # type: ignore
|
||||||
|
|
||||||
|
|||||||
2
curl.py
2
curl.py
@@ -6,6 +6,8 @@ import requests
|
|||||||
from blueprints.spotify import get_spotify_track
|
from blueprints.spotify import get_spotify_track
|
||||||
|
|
||||||
|
|
||||||
|
MAX_WIDTH = 80
|
||||||
|
|
||||||
def clean_path(path:str):
|
def clean_path(path:str):
|
||||||
path = path.strip("/ ").lower()
|
path = path.strip("/ ").lower()
|
||||||
# Strip any .html extension
|
# Strip any .html extension
|
||||||
|
|||||||
@@ -9,4 +9,5 @@ Contact [/contact]
|
|||||||
Projects [/projects]
|
Projects [/projects]
|
||||||
Tools [/tools]
|
Tools [/tools]
|
||||||
Donate [/donate]
|
Donate [/donate]
|
||||||
|
Now [/now]
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ Contact [/contact]
|
|||||||
Projects [/projects]
|
Projects [/projects]
|
||||||
Tools [/tools]
|
Tools [/tools]
|
||||||
Donate [/donate]
|
Donate [/donate]
|
||||||
|
Now [/now]
|
||||||
API [/api/v1]
|
API [/api/v1]
|
||||||
|
|
||||||
[1;36m───────────────────────────────────────────────[0m
|
[1;36m───────────────────────────────────────────────[0m
|
||||||
|
|||||||
Reference in New Issue
Block a user