from django.shortcuts import render from django.http import HttpResponse from django.template import loader import random as ra import asyncio from . import mdl from .models import Page import functools def rerender(funky): @functools.wraps(funky) def wrap(req,*args,**kwargs): with open('main/utils/navs') as b: navs=parsecat(b,4) namednavs=[{'id':blah[0], 'link':blah[1], 'text':blah[2], 'align':int(blah[3])} for blah in navs['']] out=funky(*args,**kwargs) temp=loader.get_template('main/nav.html') out['nav']=temp.render({"navs":namednavs},None) return render(req, 'main/temp.html', out) return wrap def parsecat(file,n): if not isinstance(file,str): # Assume open handle stuff=file.read() else: with open(f'main/pages/{file}') as b: stuff=b.read() cats=stuff.split('\n\n') out={} head='' out['']=[] for cat in cats: if ':' in cat[:cat.index('\n')]: # We have a category name head,cat=cat.split('\n',1) head=head[:-1] out[head]=[] else: head='' for line in cat.split('\n'): lin=line.split(',',n-1) pad=n-len(lin) lin.extend(['']*pad) out[head].append(lin) if out['']==[]: del(out['']) return out @rerender def index(): with open('main/pages/index') as b: stuff=b.read() with open('main/utils/song-ids') as b: raws=b.read() ids=raws.split('\n') stuff=stuff.format(ra.choice(ids)) return {'title':'Home','content':stuff,'date':'2021/09/20'} def lii(name,proto,link='',note=''): if link: name=f"{name}" if note: name=f"{name} ({note})" return f"\n
Interesting/useful blog posts I've found.
" arts=parsecat('articles',2) out=[] for k,v in arts.items(): out.append(f''+('
'.join(out))+'
','date':'2021/05/06'} def redirect(req,src): with open('main/pages/redirects') as b: lonks=b.read() lonks=dict([n.split(': ',1) for n in lonks.split('\n')]) return HttpResponse(status=302,headers={'Location':lonks[src]}) def md(req): loop=asyncio.get_event_loop() feed=loop.run_until_complete(mdl.makefeed(req.GET.getlist('ids',''))) return HttpResponse(feed, content_type='application/rss+xml') def vcard(req): return HttpResponse("""BEGIN:VCARD VERSION:4.0 KIND:individual FN:Zergling_man EMAIL:zerglingman@fedora.email URL:https://rakka.tk IMPP:xmpp:zergling_man@xmpp.jp;matrix:@zergling.man:perthchat.org NOTE:Anti-professionalism, pro-open standards CATEGORIES:programmer,biker SOURCE:https://rakka.tk/me.vcf END:VCARD""") @rerender def autopage(page): p=Page.objects.get(url=page) return {'title':p.title,'content':p.contents,'date':p.last_edited}