aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorAlexander Kabui2021-05-06 21:39:16 +0300
committerBonfaceKilz2021-05-07 12:01:15 +0300
commit19771ba2c54b50313675c7a29ee8a53dcb0802ce (patch)
tree57248ba0e8d5daf03b4d2e9b06c48625f005f74d /wqflask
parent2e2e4601f4cebc767854e66af2d2ca8c3e8123c9 (diff)
downloadgenenetwork2-19771ba2c54b50313675c7a29ee8a53dcb0802ce.tar.gz
add function for fetching blogs
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/markdown_routes.py62
1 files changed, 37 insertions, 25 deletions
diff --git a/wqflask/wqflask/markdown_routes.py b/wqflask/wqflask/markdown_routes.py
index b9a6f8ce..28bd6e4b 100644
--- a/wqflask/wqflask/markdown_routes.py
+++ b/wqflask/wqflask/markdown_routes.py
@@ -57,6 +57,39 @@ def get_file_from_python_search_path(pathname_suffix):
return None
+def get_blogs(user="genenetwork", repo_name="gn-docs"):
+
+ blogs = {}
+ github_url = f"https://api.github.com/repos/{user}/{repo_name}/git/trees/master?recursive=1"
+
+ repo_tree = requests.get(github_url).json()["tree"]
+
+ for data in repo_tree:
+ path_name = data["path"]
+ if path_name.startswith("blog") and path_name.endswith(".md"):
+ split_path = path_name.split("/")[1:]
+ try:
+ year, title, file_name = split_path
+ except Exception as e:
+ year, file_name = split_path
+ title = ""
+
+ subtitle = os.path.splitext(file_name)[0]
+
+ blog = {
+ "title": title,
+ "subtitle": subtitle,
+ "full_path": path_name
+ }
+
+ if year in blogs:
+ blogs[int(year)].append(blog)
+ else:
+ blogs[int(year)] = [blog]
+
+ return dict(sorted(blogs.items(), key=lambda x: x[0], reverse=True))
+
+
@glossary_blueprint.route('/')
def glossary():
return render_template(
@@ -128,34 +161,13 @@ def facilities():
return render_template("facilities.html", rendered_markdown=render_markdown("general/help/facilities.md")), 200
-@blogs_blueprint.route("/<blog_title>")
-def display_blog(blog_title):
- # should use the blog title path
-
- return render_template("blogs.html", rendered_markdown=render_markdown("blog/2021/proteome/Wang_WIlliams_Rat_Brain_Proteome_For_Blog.md"))
+@blogs_blueprint.route("/<path:blog_path>")
+def display_blog(blog_path):
+ return render_template("blogs.html", rendered_markdown=render_markdown(blog_path))
@blogs_blueprint.route("/")
def blogs_list():
-
- # should fetch this from github
-
- blogs = {"2021": [
- {
- "title": "proteome",
- "subtitle": "Wang_WIlliams_Rat_Brain_Proteome_For_Blog"
- },
- {
- "title":"xxx",
- "subtitle":"blog 2"
- }
- ],
- "2020": [
- {
- "title": "other",
- "subtitle": "other"
- }
- ]
- }
+ blogs = get_blogs()
return render_template("blogs_list.html", blogs=blogs)