wiki upgrade
This commit is contained in:
@@ -1,7 +1,78 @@
|
||||
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
|
||||
from dataclasses import dataclass
|
||||
from anytree import NodeMixin
|
||||
|
||||
class Page(SaveFileObject):
|
||||
pass
|
||||
ep=EtherpadLiteLazyAPI(
|
||||
url="http://etherpad:9101",
|
||||
exturl="https://bot.2020.fet.at/etherpad/",
|
||||
keyfile="services/etherpad/APIKEY.txt",
|
||||
groupmapper="fetwiki"
|
||||
)
|
||||
|
||||
class PageManager(SaveFileMapping):
|
||||
pass
|
||||
|
||||
|
||||
def clean_path(path):
|
||||
path = path.split("/")
|
||||
return "/".join([slugify(p) for p in path])
|
||||
|
||||
|
||||
def parse_intern_page(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)
|
||||
|
||||
@dataclass
|
||||
class Page(LazyStorageObject, NodeMixin):
|
||||
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):
|
||||
o = super().__getitem__(clean_path(key))
|
||||
o.path = clean_path(key)
|
||||
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')
|
||||
|
||||
@bp.route('/')
|
||||
@bp.route('/<path:path>')
|
||||
def web(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
|
||||
Reference in New Issue
Block a user