Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Commit

Permalink
Redirect to 404 for articles that do not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
JmPotato committed Dec 13, 2018
1 parent 39df3dd commit 64378ba
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
15 changes: 14 additions & 1 deletion Pomash/Pomash.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def get(self, page_id):
class ArticleHandler(BaseHandler):
def get(self, article_id):
article = get_article(article_id)
if(not article):
self.redirect("/404")
tags = [tag.strip() for tag in article.tag.split(",")]
self.render("article.html",
article = article,
Expand All @@ -61,6 +63,7 @@ def get(self, article_id):
valine_app_key = valine_app_key,
twitter_card = twitter_card,
twitter_username = twitter_username,
all_articles = get_all_articles(),
)

class ArticlesHandler(BaseHandler):
Expand All @@ -81,9 +84,19 @@ def get(self):

class TagHandler(BaseHandler):
def get(self, tag_name):
all_tag_articles = get_tag_articles(tag_name)
year_list = {}
for article in all_tag_articles:
year = article["datetime"].split("-")[0]
if year in year_list:
year_list[year].append(article)
else:
year_list[year] = []
year_list[year].append(article)
self.render("tag.html",
all_articles = get_all_articles(),
tag_name = tag_name,
articlesList = get_tag_articles(tag_name),
articlesList = year_list,
)

class TagsHandler(BaseHandler):
Expand Down
2 changes: 1 addition & 1 deletion Pomash/theme/clean/templates/dropbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block content %}
<div class="post">
<h1 id="title">Dropbox</h1>
<h1 id="title">Dropbox Backup</h1>
<article>
{% if not authorized %}
<div class="item">
Expand Down
13 changes: 9 additions & 4 deletions Pomash/theme/clean/templates/tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
{% block content %}
<h2>Tag: {{ tag_name }}</h2>
<ol id="posts">
{% for article in articlesList %}
<li>
<span class="meta">{{ article.datetime[:10] }}</span> <a href="/article/{{ article.article_id }}">{{ article.title }}</a>
</li>
{% for year in sorted(articlesList.keys(), reverse = True) %}
<h2>{{ year }}</h2>
<ol id="posts">
{% for i in range(len(articlesList[year])) %}
<li>
<span class="meta">{{ articlesList[year][i].datetime[:10] }}</span> <a href="/article/{{ articlesList[year][i].article_id }}">{{ articlesList[year][i].title }}</a>
</li>
{% end %}
</ol>
{% end %}
</ol>
{% end %}

0 comments on commit 64378ba

Please sign in to comment.