implement categories/tags listing
This commit is contained in:
parent
c7ea1bc1c8
commit
1fdfbe54af
36
example.py
36
example.py
|
@ -10,7 +10,7 @@ import yaml
|
|||
from slugify import slugify
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from xml.etree import ElementTree
|
||||
from flask import Flask, request, url_for, Response
|
||||
from requests import api
|
||||
from flask_micropub import MicropubClient
|
||||
|
@ -114,8 +114,10 @@ def req():
|
|||
r = requests.get(doc['photo'])
|
||||
|
||||
# generate local filename
|
||||
filename = os.path.join(os.environ.get('MICROPUB_MEDIA_PATH'), now.strftime("%Y/%m/%d"), str(now_ts) + ".jpg")
|
||||
photo_url = os.path.join(os.environ.get('MICROPUB_MEDIA_URL_PREFIX'), now.strftime("%Y/%m/%d"), str(now_ts) + ".jpg")
|
||||
filename = os.path.join(os.environ.get(
|
||||
'MICROPUB_MEDIA_PATH'), now.strftime("%Y/%m/%d"), str(now_ts) + ".jpg")
|
||||
photo_url = os.path.join(os.environ.get(
|
||||
'MICROPUB_MEDIA_URL_PREFIX'), now.strftime("%Y/%m/%d"), str(now_ts) + ".jpg")
|
||||
|
||||
# make directory if needed
|
||||
if not os.path.exists(os.path.dirname(filename)):
|
||||
|
@ -129,7 +131,6 @@ def req():
|
|||
else:
|
||||
photo_url = doc['photo']
|
||||
|
||||
|
||||
docstr = f"![image]({photo_url}) \n\n {doc['content']}"
|
||||
else:
|
||||
docstr = doc['content']
|
||||
|
@ -155,11 +156,19 @@ def req():
|
|||
# return {"hello": "world"}
|
||||
|
||||
|
||||
@app.route("/", methods=['GET'])
|
||||
@authed_endpoint
|
||||
def index():
|
||||
def parse_categories():
|
||||
|
||||
if request.args.get('q') == 'config':
|
||||
strategy = os.environ.get('MICROPUB_CATEGORY_LIST_STRATEGY')
|
||||
|
||||
if strategy == 'feed':
|
||||
tree = ElementTree.parse(os.environ.get('MICROPUB_CATEGORY_LIST_FILE'))
|
||||
tags = tree.findall('.//item/title')
|
||||
|
||||
|
||||
return {"categories": [tag.text for tag in tags] }
|
||||
|
||||
|
||||
def generate_config_json():
|
||||
return {
|
||||
"media-endpoint": "/micropub/media",
|
||||
"syndicate-to": [
|
||||
|
@ -193,6 +202,17 @@ def index():
|
|||
}
|
||||
|
||||
|
||||
@app.route("/", methods=['GET'])
|
||||
@authed_endpoint
|
||||
def index():
|
||||
|
||||
if request.args.get('q') == 'config':
|
||||
return generate_config_json()
|
||||
|
||||
elif request.args.get('q') == 'category':
|
||||
return parse_categories()
|
||||
|
||||
|
||||
@app.route('/form', methods=['GET'])
|
||||
def authform():
|
||||
return """
|
||||
|
|
Loading…
Reference in New Issue