multiple changes
This commit is contained in:
@@ -1,20 +1,22 @@
|
||||
#from misc import SaveFileMapping, SaveFileObject
|
||||
# from misc import SaveFileMapping, SaveFileObject
|
||||
from .api import EtherpadLiteLazyAPI
|
||||
from slugify import slugify
|
||||
from lazymappingstorage import LazyMappingStorage, LazyStorageObject
|
||||
from flask import Blueprint, make_response, render_template
|
||||
import bs4
|
||||
import re
|
||||
import bs4
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
from anytree import NodeMixin
|
||||
import settings
|
||||
|
||||
ep=EtherpadLiteLazyAPI(
|
||||
url="http://etherpad:9101",
|
||||
exturl="https://bot.2020.fet.at/etherpad/",
|
||||
keyfile="services/etherpad/APIKEY.txt",
|
||||
groupmapper="fetwiki"
|
||||
)
|
||||
# import html
|
||||
|
||||
ep = EtherpadLiteLazyAPI(
|
||||
url=settings.ETHERPAD_API,
|
||||
exturl=settings.ETHERPAD_EXT,
|
||||
keyfile=settings.ETHERPAD_KEYFILE,
|
||||
groupmapper=settings.ETHERPAD_GROUP,
|
||||
)
|
||||
|
||||
|
||||
def clean_path(path):
|
||||
@@ -23,56 +25,72 @@ def clean_path(path):
|
||||
|
||||
|
||||
def parse_intern_page(text):
|
||||
if not text: return text
|
||||
if not text:
|
||||
return text
|
||||
soup = bs4.BeautifulSoup(text, "html.parser")
|
||||
textNodes = soup.findAll(text=True)
|
||||
if not textNodes: return text
|
||||
for textNode in textNodes:
|
||||
text = re.sub('\[(\w+)\]','replaced!!!: - \g<1> - ',textNode)
|
||||
text = re.sub('^(\w+)\:\s?(.+)$','config param - \g<1> : \g<2> ',text)
|
||||
text = re.sub('(#[\w-]+)\s$','TAG( \g<1> ) ',text)
|
||||
print(text)
|
||||
textNode.replaceWith(text)
|
||||
|
||||
return str(soup)
|
||||
entities = {
|
||||
"internallinks": re.findall(r"\[(\w+)\]", text),
|
||||
"tags": re.findall(r"#([\w-]+)\s?", text),
|
||||
}
|
||||
if not textNodes:
|
||||
return text
|
||||
for textNode in textNodes:
|
||||
text = re.sub(r"\[(\w+)\]", r'<a href="/wiki/\g<1>">\g<1></a>', str(textNode))
|
||||
# text = re.sub(r"^(\w+)\:\s?(.+)$",'config param - \g<1> : \g<2> ',text)
|
||||
text = re.sub(r"#([\w-]+)\s?", r'<a href="/tag/\g<1>">#\g<1></a>', text)
|
||||
print(text)
|
||||
textNode.replaceWith(bs4.BeautifulSoup(text, "html.parser"))
|
||||
|
||||
return str(soup), entities
|
||||
|
||||
|
||||
@dataclass
|
||||
class Page(LazyStorageObject, NodeMixin):
|
||||
path: str=None
|
||||
count: int=1
|
||||
path: str = None
|
||||
count: int = 1
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return slugify(self.path)
|
||||
|
||||
@property
|
||||
def editlink(self):
|
||||
return ep.getPadLink(self.id)
|
||||
|
||||
@property
|
||||
def content(self):
|
||||
return parse_intern_page(ep.getPadHTML(self.id))
|
||||
|
||||
|
||||
class PageManager(LazyMappingStorage):
|
||||
filename="pages.yaml"
|
||||
object_class=Page
|
||||
def __getitem__(self,key):
|
||||
filename = "pages.yaml"
|
||||
object_class = Page
|
||||
|
||||
def __getitem__(self, key):
|
||||
o = super().__getitem__(clean_path(key))
|
||||
o.path = clean_path(key)
|
||||
if not o.path=="":
|
||||
o.parent=self["/".join(o.path.split("/")[:-1])]
|
||||
|
||||
if not o.path == "":
|
||||
o.parent = self["/".join(o.path.split("/")[:-1])]
|
||||
|
||||
return o
|
||||
def __setitem__(self,key,value):
|
||||
super().__setitem__(clean_path(key),value)
|
||||
|
||||
pages=PageManager()
|
||||
bp = Blueprint('wiki', __name__, url_prefix='/wiki')
|
||||
def __setitem__(self, key, value):
|
||||
super().__setitem__(clean_path(key), value)
|
||||
|
||||
@bp.route('/')
|
||||
@bp.route('/<path:path>')
|
||||
|
||||
pages = PageManager()
|
||||
bp = Blueprint("wiki", __name__, url_prefix="/wiki")
|
||||
|
||||
|
||||
@bp.route("/")
|
||||
@bp.route("/<path:path>")
|
||||
def web(path=""):
|
||||
|
||||
page=pages[path]
|
||||
|
||||
page = pages[path]
|
||||
pages.to_file()
|
||||
|
||||
response=make_response(render_template("wiki.html", page=page))
|
||||
response.set_cookie("sessionID",str(ep.getSessionID("andis")),path="/etherpad")
|
||||
return response
|
||||
|
||||
response = make_response(render_template("wiki.html", page=page))
|
||||
response.set_cookie("sessionID", str(ep.getSessionID("andis")), path="/etherpad")
|
||||
return response
|
||||
|
||||
@@ -99,7 +99,7 @@ class EtherpadLiteLazyAPI():
|
||||
|
||||
def getPadLink(self,padID):
|
||||
if padID is None: return "#"
|
||||
if not self.connect(): return "#"
|
||||
if not self.connect(): return "#notconnected"
|
||||
return urllib.parse.urljoin(self.exturl, 'p/' + self.group["groupID"] + '$' + str(padID))
|
||||
|
||||
def getSessionID(self, username):
|
||||
|
||||
Reference in New Issue
Block a user