This repository has been archived by the owner on Feb 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b625b1
commit ea90a4d
Showing
4 changed files
with
119 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from flask import render_template | ||
from flask import current_app as app | ||
from flask.views import MethodView | ||
from quokka.core.content.models import make_model | ||
|
||
|
||
class SiteMapView(MethodView): | ||
|
||
def get_contents(self): | ||
""" | ||
TODO: Should include extra paths, fixed paths | ||
config based paths, static paths | ||
""" | ||
return ( | ||
self.get_index() + | ||
self.get_categories() + | ||
self.get_tags() + | ||
self.get_authors() + | ||
self.get_articles_and_pages() | ||
) | ||
|
||
def get_index(self): | ||
return [ | ||
make_model(app.theme_context.get('INDEX_CATEGORY'), | ||
content_type='category') | ||
] + [ | ||
make_model(item, content_type='category') | ||
for item in app.theme_context.get('LIST_CATEGORIES', []) | ||
] | ||
|
||
def get_articles_and_pages(self): | ||
return [ | ||
make_model(item) | ||
for item in app.db.content_set( | ||
{'published': True, | ||
'content_type': {'$in': ['article', 'page']}}, | ||
sort=app.theme_context.get('ARTICLE_ORDER_BY', [('date', -1)]) | ||
) | ||
] | ||
|
||
def get_categories(self): | ||
return [ | ||
make_model('categories', content_type='fixed') | ||
] + [ | ||
make_model(item, content_type='category') | ||
for item in app.db.category_set() | ||
] | ||
|
||
def get_tags(self): | ||
return [ | ||
make_model('tags', content_type='fixed') | ||
] + [ | ||
make_model(item, content_type='tag') | ||
for item in app.db.tag_set() | ||
] | ||
|
||
def get_authors(self): | ||
return [ | ||
make_model('authors', content_type='fixed') | ||
] + [ | ||
make_model(item, content_type='author') | ||
for item in app.db.author_set() | ||
] | ||
|
||
def get(self): | ||
return render_template('sitemap.xml', contents=self.get_contents()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{%- macro render_item(item) -%} | ||
<url> | ||
<loc>{{item.external_url|safe}}</loc> | ||
{% if item.is_content %} | ||
<lastmod>{{item.modified.strftime('%Y-%m-%d')}}</lastmod> | ||
{% endif %} | ||
<changefreq>daily</changefreq> | ||
<priority>0.2</priority> | ||
</url> | ||
{%- endmacro -%} | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | ||
{%- for item in contents -%} | ||
{{ render_item(item) }} | ||
{%- endfor -%} | ||
</urlset> |