Пример #1
0
 def get(self):
     articles = models.get_latest_articles()
     if len(articles) > 0:
         first_article = articles[0]
     else:
         first_article = None
     return helpers.render_template(self, 'webviews/front.html', {'articles': models.get_articles(), 'first_article': first_article})
Пример #2
0
    def post(self):
        parser_copy = parser.copy()
        parser_copy.add_argument('_id', required=False)

        try:
            data = parser_copy.parse_args()
            _id = data.get('_id', None)
        except:
            _id = None
        
        return models.get_articles(_id=_id)
Пример #3
0
def update_sitemap(changefreq='monthly', priority=0.7):
    """
    sitemapを全て更新する
    カテゴリページは含めない
    :param changefreq: 記事の更新頻度
    :param priority: 記事の優先度
    :return:
    """
    # 公開済みのものだけ取得
    articles = get_articles(False)

    # URL
    locs = [
        '{}/category/{}/{}'.format(DOMAIN, article['category'],
                                   article['slug']) for article in articles
    ]

    # 最終更新日
    lastmods = [
        article['last_update'].strftime('%Y-%m-%d') for article in articles
    ]

    # 上書きする
    sitemap = open('sitemap.xml', 'w')
    sitemap.write('<?xml version="1.0" encoding="UTF-8"?>\n')
    sitemap.write(
        '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n')
    sitemap.write('    <url>\n')
    sitemap.write('        <loc>{}/</loc>\n'.format(DOMAIN))
    sitemap.write('        <lastmod>{}</lastmod>\n'.format(
        datetime.now().strftime('%Y-%m-%d')))
    sitemap.write('        <changefreq>always</changefreq>\n')
    sitemap.write('        <priority>1.0</priority>\n')
    sitemap.write('    </url>\n')

    for loc, lastmod in zip(locs, lastmods):
        sitemap.write('    <url>\n')
        sitemap.write('        <loc>{}/</loc>\n'.format(loc))
        sitemap.write('        <lastmod>{}</lastmod>\n'.format(lastmod))
        sitemap.write(
            '        <changefreq>{}</changefreq>\n'.format(changefreq))
        sitemap.write('        <priority>{}</priority>\n'.format(priority))
        sitemap.write('    </url>\n')

    sitemap.write('</urlset>\n')
    sitemap.close()
Пример #4
0
 def index(self):
     heads, results = models.get_articles()
     return render_template('articles.html',
                            heads=heads,
                            results=results,
                            searchUrl='articles/search')
Пример #5
0
 def get(self):
     return helpers.render_template(self, 'webviews/jsonfeed.html', {'items': models.get_articles()})