canonicalwebteam.blog
1.0.0
此擴展程序使您可以在燒瓶應用程序中添加一個簡單的前端部分。所有文章均通過JSON API從Canonical的WordPress後端取出。
該擴展名提供了一個帶有3個路由的藍圖:
要在項目中安裝此擴展程序,您可以使用PIP;
pip3 install canonicalwebteam.blog另請參見PIP安裝文檔。
對於本地開發,最好使用Ubuntu.com等網站項目之一測試該模塊。有關更多信息,請遵循本指南(僅內部)。
該模塊期望在blog/index.html , blog/article.html , blog/blog-card.html , blog/archives.html , blog/upcoming.html和blog/author.html上期望HTML模板。
這些模板的一個示例可以在https://github.com/canonical-websites/jp.ubuntu.com/tree/master/master/templates/blog中找到。
在您的應用中,您可以執行以下操作:
import flask
import talisker . requests
from flask_reggie import Reggie
from canonicalwebteam . blog import BlogViews , build_blueprint , BlogAPI
app = flask . Flask ( __name__ )
Reggie (). init_app ( app )
session = talisker . requests . get_session ()
blog = build_blueprint (
BlogViews (
api = BlogAPI ( session = session ),
)
)
app . register_blueprint ( blog , url_prefix = "/blog" )您可以通過以下可選參數自定義博客:
blog = build_blueprint (
BlogViews (
blog_title = "Blog" ,
blog_path = "blog" ,
tag_ids = [ 1 , 12 , 112 ],
exclude_tags = [ 26 , 34 ],
per_page = 12 ,
feed_description = "The Ubuntu Blog Feed" ,
api = BlogAPI (
session = session ,
use_image_template = True ,
thumbnail_width = 330 ,
thumbnail_height = 185 ,
),
)
)所有測試都可以使用./setup.py test進行。
所有API呼叫都被VCR捕獲,並保存為fixtures目錄。如果API更新,則可以通過刪除fixtures目錄並重新計算測試來輕鬆更新所有固定裝置。
要執行此運行rm -rf fixtures && ./setup.py test 。