이 확장자를 사용하면 플라스크 앱에 간단한 프론트 엔드 섹션을 추가 할 수 있습니다. 모든 기사는 JSON API를 통해 Canonical의 WordPress 백엔드에서 가져옵니다.
이 확장자는 3 개의 경로가있는 청사진을 제공합니다.
이 확장을 프로젝트에 요구 사항으로 설치하려면 PIP를 사용할 수 있습니다.
pip3 install canonicalwebteam.blogPIP 설치 문서도 참조하십시오.
지역 개발의 경우 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/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 실행합니다.