def init_docs(app): discourse_index_id = 1087 tutorials_index_topic_id = 2628 tutorials_url_prefix = "/tutorials" session = talisker.requests.get_session() discourse_docs = Docs( parser=DocParser( api=DiscourseAPI( base_url="https://discourse.charmhub.io/", session=session, api_key=DISCOURSE_API_KEY, api_username=DISCOURSE_API_USERNAME, get_topics_query_id=2, ), index_topic_id=discourse_index_id, url_prefix="/docs", tutorials_index_topic_id=tutorials_index_topic_id, tutorials_url_prefix=tutorials_url_prefix, ), document_template="docs/document.html", url_prefix="/docs", ) discourse_docs.init_app(app) sdk_docs_id = 4449 sdk_docs = Docs( parser=DocParser( api=DiscourseAPI( base_url="https://discourse.charmhub.io/", session=session, api_key=DISCOURSE_API_KEY, api_username=DISCOURSE_API_USERNAME, get_topics_query_id=2, ), index_topic_id=sdk_docs_id, url_prefix="/docs/sdk", tutorials_index_topic_id=tutorials_index_topic_id, tutorials_url_prefix=tutorials_url_prefix, ), document_template="docs/document.html", url_prefix="/docs/sdk", blueprint_name="sdk_docs", ) sdk_docs.init_app(app) app.add_url_rule( "/docs/search", "docs-search", build_search_view( session=session, site="juju.is/docs", template_path="docs/search.html", ), )
def init_docs(app, url_prefix): session = talisker.requests.get_session() discourse_docs = Docs( parser=DocParser( api=DiscourseAPI( base_url="https://forum.snapcraft.io/", session=session, api_key=DISCOURSE_API_KEY, api_username=DISCOURSE_API_USERNAME, get_topics_query_id=2, ), index_topic_id=11127, url_prefix=url_prefix, tutorials_index_topic_id=15409, tutorials_url_prefix="/tutorials", ), document_template="docs/document.html", url_prefix=url_prefix, ) discourse_docs.init_app(app) app.add_url_rule( "/docs/search", "docs-search", build_search_view( session=session, site="snapcraft.io/docs", template_path="docs/search.html", ), )
def init_docs(app, url_prefix): discourse_docs = Docs( parser=DocParser( api=DiscourseAPI( base_url="https://forum.snapcraft.io/", session=talisker.requests.get_session(), ), index_topic_id=11127, url_prefix=url_prefix, ), document_template="docs/document.html", url_prefix=url_prefix, ) discourse_docs.init_app(app) app.add_url_rule( "/docs/search", "docs-search", build_search_view( session=talisker.requests.get_session(), site="snapcraft.io/docs", template_path="docs/search.html", ), )
def init_tutorials(app, url_prefix): session = talisker.requests.get_session() discourse_docs = Docs( parser=DocParser( api=DiscourseAPI(base_url="https://discourse.charmhub.io/", session=session), index_topic_id=2628, category_id=34, url_prefix=url_prefix, ), document_template="tutorials/tutorial.html", url_prefix=url_prefix, blueprint_name="tutorials", ) @app.route(url_prefix) def index(): page = flask.request.args.get("page", default=1, type=int) posts_per_page = 12 discourse_docs.parser.parse() metadata = discourse_docs.parser.metadata total_pages = math.ceil(len(metadata) / posts_per_page) return flask.render_template( "tutorials/index.html", navigation=discourse_docs.parser.navigation, forum_url=discourse_docs.parser.api.base_url, metadata=metadata, page=page, posts_per_page=posts_per_page, total_pages=total_pages, active_section="tutorials", ) discourse_docs.init_app(app)
def init_docs(app, url_prefix): discourse_index_id = 3394 session = talisker.requests.get_session() discourse_docs = Docs( parser=DocParser( api=DiscourseAPI(base_url="https://discourse.charmhub.io/", session=session), index_topic_id=discourse_index_id, url_prefix=url_prefix, ), document_template="docs/document.html", url_prefix=url_prefix, ) discourse_docs.init_app(app) app.add_url_rule( "/docs/search", "docs-search", build_search_view( session=session, site="charmhub.io/docs", template_path="docs/search.html", ), )
def init_tutorials(app, url_prefix): discourse_index_id = 3393 category_id = 30 session = talisker.requests.get_session() tutorials_docs = Docs( parser=DocParser( api=DiscourseAPI(base_url="https://discourse.juju.is/", session=session), index_topic_id=discourse_index_id, category_id=category_id, url_prefix=url_prefix, ), document_template="tutorials/tutorial.html", url_prefix=url_prefix, blueprint_name="tutorials", ) @app.route(url_prefix) def tutorials(): page = flask.request.args.get("page", default=1, type=int) topic = flask.request.args.get("topic", default=None, type=str) sort = flask.request.args.get("sort", default=None, type=str) posts_per_page = 15 tutorials_docs.parser.parse() if not topic: metadata = tutorials_docs.parser.metadata else: metadata = [ doc for doc in tutorials_docs.parser.metadata if topic in doc["categories"] ] if sort == "difficulty-desc": metadata = sorted(metadata, key=lambda k: k["difficulty"], reverse=True) if sort == "difficulty-asc" or not sort: metadata = sorted(metadata, key=lambda k: k["difficulty"], reverse=False) total_pages = math.ceil(len(metadata) / posts_per_page) return flask.render_template( "tutorials/index.html", navigation=tutorials_docs.parser.navigation, forum_url=tutorials_docs.parser.api.base_url, metadata=metadata, page=page, topic=topic, sort=sort, posts_per_page=posts_per_page, total_pages=total_pages, ) tutorials_docs.init_app(app)
def details_docs(entity_name, slug=None): package = app.store_api.get_item_details(entity_name, fields=FIELDS) package = logic.add_store_front_data(package) docs_url_prefix = f"/{package['name']}/docs" # Fake package discourse topic package["docs_topic"] = 3568 docs = DocParser( api=discourse_api, index_topic_id=package["docs_topic"], url_prefix=docs_url_prefix, ) docs.parse() body_html = docs.index_document["body_html"] topic_path = docs.index_document["topic_path"] if slug: topic_id = docs.resolve_path(slug) # topic = docs.api.get_topic(topic_id) # body_html = docs.parse_topic(topic) slug_docs = DocParser( api=discourse_api, index_topic_id=topic_id, url_prefix=docs_url_prefix, ) slug_docs.parse() body_html = slug_docs.index_document["body_html"] topic_path = slug_docs.index_document["topic_path"] context = { "package": package, "navigation": docs.navigation, "body_html": body_html, "last_update": docs.index_document["updated"], "forum_url": docs.api.base_url, "topic_path": topic_path, } return render_template("details/docs.html", **context)
def init_docs(app): discourse_index_id = 1087 session = talisker.requests.get_session() discourse_docs = Docs( parser=DocParser( api=DiscourseAPI(base_url="https://discourse.charmhub.io/", session=session), index_topic_id=discourse_index_id, url_prefix="/docs", ), document_template="docs/document.html", url_prefix="/docs", ) discourse_docs.init_app(app) sdk_docs_id = 4449 sdk_docs = Docs( parser=DocParser( api=DiscourseAPI(base_url="https://discourse.charmhub.io/", session=session), index_topic_id=sdk_docs_id, url_prefix="/docs/sdk", ), document_template="docs/document.html", url_prefix="/docs/sdk", blueprint_name="sdk_docs", ) sdk_docs.init_app(app) app.add_url_rule( "/docs/search", "docs-search", build_search_view( session=session, site="juju.is/docs", template_path="docs/search.html", ), )
def details_docs(entity_name, path=None): channel_request = request.args.get("channel", default=None, type=str) extra_fields = [ "default-release.revision.metadata-yaml", ] package = get_package( entity_name, channel_request, FIELDS.copy() + extra_fields ) if not package["store_front"]["docs_topic"]: return render_template( "details/empty-docs.html", package=package, channel_requested=channel_request, ) docs_url_prefix = f"/{package['name']}/docs" docs = DocParser( api=discourse_api, index_topic_id=package["store_front"]["docs_topic"], url_prefix=docs_url_prefix, ) docs.parse() if path: try: topic_id = docs.resolve_path(path)[0] except PathNotFoundError: abort(404) topic = docs.api.get_topic(topic_id) else: topic = docs.index_topic document = docs.parse_topic(topic) context = { "package": package, "navigation": docs.navigation, "body_html": document["body_html"], "last_update": document["updated"], "forum_url": docs.api.base_url, "topic_path": document["topic_path"], "channel_requested": channel_request, } return render_template("details/docs.html", **context)
def openstack_install(): """ Openstack install docs Instructions for openstack installation pulled from Discourse """ discourse_api = DiscourseAPI( base_url="https://discourse.ubuntu.com/", session=session ) openstack_install_parser = DocParser( api=discourse_api, index_topic_id=23346, url_prefix="/openstack/install", ) openstack_install_docs = Docs( parser=openstack_install_parser, document_template="/openstack/install.html", url_prefix="/openstack/install", blueprint_name="openstack-install-docs", ) singlenode_topic = openstack_install_docs.parser.api.get_topic(21427) singlenode_topic_soup = BeautifulSoup( singlenode_topic["post_stream"]["posts"][0]["cooked"], features="html.parser", ) singlenode_content = openstack_install_parser._process_topic_soup( singlenode_topic_soup ) openstack_install_docs.parser._replace_lightbox(singlenode_topic_soup) multinode_topic = openstack_install_docs.parser.api.get_topic(18259) multinode_topic_soup = BeautifulSoup( multinode_topic["post_stream"]["posts"][0]["cooked"], features="html.parser", ) multinode_content = openstack_install_docs.parser._process_topic_soup( multinode_topic_soup ) openstack_install_docs.parser._replace_lightbox(multinode_topic_soup) return flask.render_template( "openstack/install.html", single_node=str(singlenode_content), multi_node=str(multinode_content), )
response.cache_control.max_age = 86400 response.cache_control.public = True return response app.add_url_rule("/", view_func=template_finder_view) app.add_url_rule( "/docs/search", "search", build_search_view( session=session, site="vanillaframework.io/docs", template_path="docs/search.html", ), ) app.add_url_rule("/<path:subpath>", view_func=template_finder_view) discourse_docs = Docs( parser=DocParser( api=DiscourseAPI(base_url="https://discourse.ubuntu.com/", session=session), index_topic_id= 27037, # https://discourse.ubuntu.com/t/design-system-website-config/27037 url_prefix="/design", ), document_template="/_layouts/docs_discourse.html", url_prefix="/design", ) discourse_docs.init_app(app)
Docs, DocParser, ) # Rename your project below app = FlaskBase( __name__, "microstack.run", template_folder="../templates", static_folder="../static", ) session = talisker.requests.get_session() doc_parser = DocParser( api=DiscourseAPI(base_url="https://discourse.ubuntu.com/", session=session), index_topic_id=18212, url_prefix="/docs", ) if app.debug: doc_parser.api.session.adapters["https://"].timeout = 99 discourse_docs = Docs( parser=doc_parser, document_template="docs/document.html", url_prefix="/docs", ) discourse_docs.init_app(app) @app.route("/")
template_finder_view = TemplateFinder.as_view("template_finder") template_finder_view._exclude_xframe_options_header = True app.add_url_rule("/", view_func=template_finder_view) app.add_url_rule("/snaps", view_func=search_snaps) app.add_url_rule("/core/build", view_func=build) app.add_url_rule("/core/build", view_func=post_build, methods=["POST"]) app.add_url_rule( "/core/build/notify", view_func=notify_build, methods=["POST"] ) app.add_url_rule("/<path:subpath>", view_func=template_finder_view) url_prefix = "/server/docs" server_docs = Docs( parser=DocParser( api=discourse_api, category_id=26, index_topic_id=11322, url_prefix=url_prefix, ), document_template="/templates/docs/discourse.html", url_prefix=url_prefix, ) server_docs.init_app(app) # Allow templates to be queried from discourse.ubuntu.com app.add_url_rule( "/templates/<filename>", "templates", view_func=show_template, ) tutorials_path = "/tutorials"
import talisker.requests from canonicalwebteam.discourse import DiscourseAPI, DocParser, Docs discourse_index_id = 14129 session = talisker.requests.get_session() discourse_docs = Docs( parser=DocParser( api=DiscourseAPI(base_url="https://discourse.ubuntu.com/", session=session), index_topic_id=discourse_index_id, url_prefix="/guides", ), document_template="guides.html", url_prefix="/guides", )
app = FlaskBase( __name__, "dqlite.io", template_folder="../templates", static_folder="../static", template_404="404.html", template_500="500.html", ) session = talisker.requests.get_session() docs_url_prefix = "/docs" discourse_docs = Docs( parser=DocParser( api=DiscourseAPI( base_url="https://discourse.dqlite.io/", session=session, ), index_topic_id=34, url_prefix=docs_url_prefix, ), document_template="docs/document.html", url_prefix=docs_url_prefix, ) app.add_url_rule( "/docs/search", "docs-search", build_search_view( session=session, site="https://dqlite.io/docs", template_path="docs/search.html", ),
# Rename your project below app = FlaskBase( __name__, "microk8s.io", template_folder="../templates", static_folder="../static", template_404="404.html", template_500="500.html", ) session = talisker.requests.get_session() discourse = Docs( parser=DocParser( api=DiscourseAPI(base_url="https://discuss.kubernetes.io/", session=session), index_topic_id=11243, url_prefix="/docs", ), document_template="docs/document.html", url_prefix="/docs", ) app.add_url_rule( "/docs/search", "docs-search", build_search_view( session=session, site="microk8s.io/docs", template_path="docs/search.html", ), ) discourse.init_app(app)
# All other routes template_finder_view = TemplateFinder.as_view("template_finder") app.add_url_rule("/", view_func=template_finder_view) app.add_url_rule("/snaps", view_func=search_snaps) app.add_url_rule("/core/build", view_func=build) app.add_url_rule("/core/build", view_func=post_build, methods=["POST"]) app.add_url_rule( "/core/build/notify", view_func=notify_build, methods=["POST"] ) app.add_url_rule("/<path:subpath>", view_func=template_finder_view) url_prefix = "/server/docs" server_docs = Docs( parser=DocParser( api=discourse_api, category_id=26, index_topic_id=11322, url_prefix=url_prefix, ), document_template="/docs/document.html", url_prefix=url_prefix, ) server_docs.init_app(app) # Allow templates to be queried from discourse.ubuntu.com app.add_url_rule( "/templates/<filename>", "templates", lambda filename: ( flask.render_template(f"templates/{filename}.html"), {"Access-Control-Allow-Origin": "*"}, ),
"takeovers/index.html", takeovers=takeovers, ) app.add_url_rule("/16-04", view_func=sixteen_zero_four) app.add_url_rule("/takeovers.json", view_func=takeovers_json) app.add_url_rule("/takeovers", view_func=takeovers_index) engage_pages.init_app(app) core_services_guide_url = "/core/services/guide" core_services_guide = Docs( parser=DocParser( api=discourse_api, index_topic_id=27473, url_prefix=core_services_guide_url, ), document_template="core/services/guide/document.html", url_prefix=core_services_guide_url, blueprint_name="core-services-guide", ) # app.add_url_rule( # "/core/services/guide/search", # "core-services-guide-search", # build_search_view( # session=session, # site="ubuntu.com/core/services/guide", # template_path="core/services/guide/search-results.html", # search_engine_id=search_engine_id,
# All other routes template_finder_view = TemplateFinder.as_view("template_finder") app.add_url_rule("/", view_func=template_finder_view) app.add_url_rule("/snaps", view_func=search_snaps) app.add_url_rule("/core/build", view_func=build) app.add_url_rule("/core/build", view_func=post_build, methods=["POST"]) app.add_url_rule("/core/build/notify", view_func=notify_build, methods=["POST"]) app.add_url_rule("/<path:subpath>", view_func=template_finder_view) url_prefix = "/server/docs" server_docs = Docs( parser=DocParser( api=discourse_api, category_id=26, index_topic_id=11322, url_prefix=url_prefix, ), document_template="/docs/document.html", url_prefix=url_prefix, ) server_docs.init_app(app) # Allow templates to be queried from discourse.ubuntu.com app.add_url_rule( "/templates/<filename>", "templates", lambda filename: ( flask.render_template(f"templates/{filename}.html"), { "Access-Control-Allow-Origin": "*"
def setUp(self): """ Set up Flask app with Discourse extension for testing And set up mocking for discourse.example.com """ # Suppress annoying warnings from HTTPretty # See: https://github.com/gabrielfalcao/HTTPretty/issues/368 warnings.filterwarnings( "ignore", category=ResourceWarning, message="unclosed.*" ) # Enable HTTPretty and set up mock URLs httpretty.enable() register_uris() template_folder = f"{this_dir}/fixtures/templates" app = flask.Flask("main", template_folder=template_folder) app_no_nav = flask.Flask("no-nav", template_folder=template_folder) app_no_mappings = flask.Flask( "no-mappings", template_folder=template_folder ) app_broken_mappings = flask.Flask( "broken-mappings", template_folder=template_folder ) app_no_category = flask.Flask( "no-category", template_folder=template_folder ) app_url_prefix = flask.Flask( "url-prefix", template_folder=template_folder ) app.testing = True app_no_nav.testing = True app_no_mappings.testing = True app_broken_mappings.testing = True app_no_category.testing = True app_url_prefix.testing = True discourse_api = DiscourseAPI( base_url="https://discourse.example.com/", session=requests.Session(), ) Docs( parser=DocParser( api=discourse_api, category_id=2, index_topic_id=34, url_prefix="/", ), document_template="document.html", url_prefix="/", ).init_app(app) Docs( parser=DocParser( api=discourse_api, category_id=2, index_topic_id=42, url_prefix="/", ), document_template="document.html", url_prefix="/", ).init_app(app_no_nav) Docs( parser=DocParser( api=discourse_api, category_id=2, index_topic_id=35, url_prefix="/", ), document_template="document.html", url_prefix="/", ).init_app(app_no_mappings) Docs( parser=DocParser( api=discourse_api, category_id=2, index_topic_id=36, url_prefix="/", ), document_template="document.html", url_prefix="/", ).init_app(app_broken_mappings) Docs( parser=DocParser( api=discourse_api, index_topic_id=37, url_prefix="/" ), document_template="document.html", url_prefix="/", ).init_app(app_no_category) Docs( parser=DocParser( api=discourse_api, index_topic_id=38, url_prefix="/docs" ), document_template="document.html", url_prefix="/docs", ).init_app(app_url_prefix) self.client = app.test_client() self.client_no_nav = app_no_nav.test_client() self.client_no_mappings = app_no_mappings.test_client() self.client_broken_mappings = app_broken_mappings.test_client() self.client_no_category = app_no_category.test_client() self.client_url_prefix = app_url_prefix.test_client()