canonicalwebteam.discourse
5.7.3: Read href from masked links in metadata
燒瓶擴展以整合到您網站的文檔生成的話語內容。該項目以前被命名為discourse_docs 。
有關如何在話語中編寫文檔頁面以供本模塊編寫文檔頁面以及如何配置網站使用該模塊的文檔頁面,可以在規範的話語中找到。
可以在示例文件夾中找到用於examples頁面的示例燒瓶模板。有關更多信息,請參考該文件夾中的讀數。
使用PIP安裝項目: pip install canonicalwebteam.discourse
您可以使用自己的設置添加項目上的擴展名,至少可以替換base_url和index_topic_id :
import talisker . requests
from canonicalwebteam . discourse import DiscourseAPI , Tutorials , TutorialParser
app = Flask ( "myapp" )
session = talisker . requests . get_session ()
discourse = Tutorials (
parser = TutorialParser (
api = DiscourseAPI (
base_url = "https://forum.example.com/" , session = session
),
index_topic_id = 321 ,
url_prefix = "/docs" ,
),
document_template = "docs/document.html" ,
url_prefix = "/docs" ,
)
discourse . init_app ( app )添加此信息後,您需要將file document.html添加到模板文件夾中。
對於本地開發,最好使用Ubuntu.com等網站項目之一測試該模塊。有關更多信息,請遵循本指南(僅內部)。
可以使用TOX進行測試:
pip3 install tox # Install tox
tox # Run tests
tox -e lint # Check the format of Python code
tox -e format # Reformat the Python code 因為您正在查看一個受保護的主題,所以您必須提供api_key和api_username 。您還需要一個索引主題ID,您可以從course.ubuntu.com獲得。您的索引主題必須包含一個元數據部分。請訪問GaintParser以獲取有關該結構的更多信息。鼓勵您使用不與存在的藍圖相撞的藍圖名稱。這些模板必須匹配所示參數中提供的模板。
這是實現的示例:
engage_pages = EngagePages (
api = DiscourseAPI (
base_url = "https://discourse.ubuntu.com/" ,
session = session ,
get_topics_query_id = 14 ,
api_key = DISCOURSE_API_KEY , # replace with your API key
api_username = DISCOURSE_API_USERNAME , # replace with correspoding username
),
category_id = 51 ,
page_type = "engage-pages" , # one of ["engage-pages", "takeovers"]
exclude_topics = [] # this is a list of topic ids that we want to exclude from Markdown error checks
additional_metadata_validation = [] # list of additional keys in the metadata table that you want to validate existence for e.g. language
)在您的項目中,您需要創建自己的觀點:
app . add_url_rule (
"/engage" , view_func = build_engage_index ( engage_pages )
)
app . add_url_rule (
"/engage/<path>" , view_func = single_engage_page ( engage_pages )
)build_engage_index將是您的參與頁列表的視圖,您可以使用方法EngagagePages(args).get_index()獲得該列表。single_engage_page將是您的單個參與頁面視圖,您可以使用EngagePages(args).get_engage_page(path)獲得它同樣,對於收購,您只需要通過page_type="takeovers"即可。
EngagePages(args).get_index()的收購列表。EngagePages(args).parse_active_takeovers() 。 get_index提供了兩個附加的參數limit和offset ,以提供分頁功能。他們分別默認為50和0。limit=-1exceptions.py下使用MaxLimitError來處理過多的限制。默認情況下,它會超過500時會引起錯誤