aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzsloan2021-05-07 15:57:25 +0000
committerzsloan2021-05-07 15:57:25 +0000
commit93cb2c7b2e5cabcf95a49fbdcddae8cc94563aa2 (patch)
treea27cc593955cd4e07cba356b27a9316c721c0c74
parent1895e953747bb5d9d41f249408590e187027b266 (diff)
parent5c474e24fa43cdffacd698cd3a1e9e5182a49016 (diff)
downloadgenenetwork2-93cb2c7b2e5cabcf95a49fbdcddae8cc94563aa2.tar.gz
Merge branch 'testing' of github.com:genenetwork/genenetwork2 into testing
-rw-r--r--wqflask/wqflask/__init__.py2
-rw-r--r--wqflask/wqflask/markdown_routes.py54
-rw-r--r--wqflask/wqflask/templates/base.html1
-rw-r--r--wqflask/wqflask/templates/blogs.html12
-rw-r--r--wqflask/wqflask/templates/blogs_list.html52
-rwxr-xr-xwqflask/wqflask/templates/index_page.html25
6 files changed, 145 insertions, 1 deletions
diff --git a/wqflask/wqflask/__init__.py b/wqflask/wqflask/__init__.py
index a2bf3085..bf5e094b 100644
--- a/wqflask/wqflask/__init__.py
+++ b/wqflask/wqflask/__init__.py
@@ -12,6 +12,7 @@ from wqflask.markdown_routes import links_blueprint
from wqflask.markdown_routes import policies_blueprint
from wqflask.markdown_routes import environments_blueprint
from wqflask.markdown_routes import facilities_blueprint
+from wqflask.markdown_routes import blogs_blueprint
app = Flask(__name__)
@@ -29,6 +30,7 @@ app.register_blueprint(links_blueprint, url_prefix="/links")
app.register_blueprint(policies_blueprint, url_prefix="/policies")
app.register_blueprint(environments_blueprint, url_prefix="/environments")
app.register_blueprint(facilities_blueprint, url_prefix="/facilities")
+app.register_blueprint(blogs_blueprint, url_prefix="/blogs")
@app.before_request
diff --git a/wqflask/wqflask/markdown_routes.py b/wqflask/wqflask/markdown_routes.py
index c27ff143..b81bfb55 100644
--- a/wqflask/wqflask/markdown_routes.py
+++ b/wqflask/wqflask/markdown_routes.py
@@ -2,17 +2,21 @@
Render pages from github, or if they are unavailable, look for it else where
"""
+
import requests
import markdown
import os
import sys
-from bs4 import BeautifulSoup
+from bs4 import BeautifulSoup # type: ignore
from flask import send_from_directory
from flask import Blueprint
from flask import render_template
+from typing import Dict
+from typing import List
+
glossary_blueprint = Blueprint('glossary_blueprint', __name__)
references_blueprint = Blueprint("references_blueprint", __name__)
environments_blueprint = Blueprint("environments_blueprint", __name__)
@@ -20,6 +24,8 @@ links_blueprint = Blueprint("links_blueprint", __name__)
policies_blueprint = Blueprint("policies_blueprint", __name__)
facilities_blueprint = Blueprint("facilities_blueprint", __name__)
+blogs_blueprint = Blueprint("blogs_blueprint", __name__)
+
def render_markdown(file_name, is_remote_file=True):
"""Try to fetch the file name from Github and if that fails, try to
@@ -55,6 +61,40 @@ def get_file_from_python_search_path(pathname_suffix):
return None
+def get_blogs(user: str = "genenetwork",
+ repo_name: str = "gn-docs") -> dict:
+
+ blogs: Dict[int, List] = {}
+ 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(
@@ -124,3 +164,15 @@ def policies():
@facilities_blueprint.route("/")
def facilities():
return render_template("facilities.html", rendered_markdown=render_markdown("general/help/facilities.md")), 200
+
+
+@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():
+ blogs = get_blogs()
+
+ return render_template("blogs_list.html", blogs=blogs)
diff --git a/wqflask/wqflask/templates/base.html b/wqflask/wqflask/templates/base.html
index e6f22deb..ddb1d272 100644
--- a/wqflask/wqflask/templates/base.html
+++ b/wqflask/wqflask/templates/base.html
@@ -69,6 +69,7 @@
<ul class="dropdown-menu">
<li><a href="{{ url_for('references_blueprint.references') }}">References</a></li>
<li><a href="/tutorials">Tutorials/Primers</a></li>
+ <li><a href="{{ url_for('blogs_blueprint.blogs_list') }}">Blogs</a></li>
<li><a href="{{ url_for('glossary_blueprint.glossary') }}">Glossary of Term</a></li>
<li><a href="http://gn1.genenetwork.org/faq.html">FAQ</a></li>
<li><a href="{{ url_for('policies_blueprint.policies') }}">Policies</a></li>
diff --git a/wqflask/wqflask/templates/blogs.html b/wqflask/wqflask/templates/blogs.html
new file mode 100644
index 00000000..314eb733
--- /dev/null
+++ b/wqflask/wqflask/templates/blogs.html
@@ -0,0 +1,12 @@
+{% extends "base.html" %}
+{% block title %}Blogs {% endblock %}
+{% block css %}
+<link rel="stylesheet" type="text/css" href="/static/new/css/markdown.css" />
+{% endblock %}
+{% block content %}
+<div class="github-btn-container">
+</div>
+<div id="markdown" class="container">
+ {{ rendered_markdown|safe }}
+</div>
+{% endblock %} \ No newline at end of file
diff --git a/wqflask/wqflask/templates/blogs_list.html b/wqflask/wqflask/templates/blogs_list.html
new file mode 100644
index 00000000..6bad4628
--- /dev/null
+++ b/wqflask/wqflask/templates/blogs_list.html
@@ -0,0 +1,52 @@
+{% extends "base.html" %}
+{% block title %}Blogs {% endblock %}
+{% block css %}
+<style type="text/css">
+.container {
+ height: 100vh;
+}
+
+.blog_year {
+ font-weight: bold;
+ font-size: 48px;
+ padding: 12px 10px;
+}
+
+.blog_title {
+ padding: 10px 15px;
+
+}
+
+
+
+.blog_title a {
+ font-size: 1.3em;
+ padding-left: 10px;
+ letter-spacing: 0.07em;
+ text-decoration: underline;
+}
+</style>
+<link rel="stylesheet" type="text/css" href="/static/new/css/markdown.css" />
+{% endblock %}
+{% block content %}
+<div id="markdown" class="container">
+ <div>
+ {% for year, year_blogs in blogs.items() %}
+ <div class="blog_year">
+ <h3>{{year}}</h3>
+ </div>
+ {%for blog in year_blogs%}
+ <div>
+ <div class="blog_title">
+ <ul>
+ <li>
+ <a href="{{ url_for('blogs_blueprint.display_blog',blog_path = blog.full_path)}}">{{blog['subtitle']}}</a>
+ </li>
+ </ul>
+ </div>
+ </div>
+ {% endfor %}
+ {%endfor%}
+ </div>
+</div>
+{% endblock %} \ No newline at end of file
diff --git a/wqflask/wqflask/templates/index_page.html b/wqflask/wqflask/templates/index_page.html
index 338c8e2f..7b103305 100755
--- a/wqflask/wqflask/templates/index_page.html
+++ b/wqflask/wqflask/templates/index_page.html
@@ -3,6 +3,31 @@
{% block css %}
<style TYPE="text/css">
p.interact { display: none; }
+
+
+
+
+ .tweet {
+
+ padding:5px;
+ color:#000;
+
+ }
+
+ .media {
+ padding-bottom:10px;
+ border-bottom: 1px solid #c8ccc9;
+ }
+
+ .media img {
+
+ width: 95%;
+ height: 100%;
+ border-radius: 5px;
+ /*transform: scale(1.1); image small?*/
+ border:1px solid #c8ccc9;
+
+ }
</style>
{% endblock %}
{% block content %}