Skip to main content

discourse-docsify

Flask extension to source data from discourse forum posts into a docsify (documentation) website.

This allows you to leverage docsify's features while still benefiting from discourse's forum nature: beautiful documentation anyone within your community may expand on and contribute to.

This project was inspired by this canonicalwebeteam's repo.

Setup

Install with

pip install discourse-docsify

You can initialize the extension directly:

from flask import Flask
from discourse_docsify import Docs

app = Flask(__name__)
# for more config options and additional parameters see below
docs = Docs(app, config={
    'DOCS_HOMEPAGE_TITLE': 'My Documentation Website',
    'DOCS_DISCOURSE_API_USERNAME': '...',
    'DOCS_DISCOURSE_API_KEY': '...',
    'DOCS_DISCOURSE_BASE_URL': '...',
    'DOCS_DISCOURSE_INDEX_TOPIC_ID': '...',
})

or by doing

from flask import Flask
from discourse_docsify import Docs

# for more config options and additional parameters see below
docs = Docs(config={
    'DOCS_HOMEPAGE_TITLE': 'My Documentation Website',
    'DOCS_DISCOURSE_API_USERNAME': '...',
    'DOCS_DISCOURSE_API_KEY': '...',
    'DOCS_DISCOURSE_BASE_URL': '...',
    'DOCS_DISCOURSE_INDEX_TOPIC_ID': '...',
})

app = Flask(__name__)
docs.init_app(app)

No plugin needs to be installed on discourse, you simply need a valid API key.

Index topic

The index topic contains the homepage content, a list of urls mappings to translate documentation paths into forum topics and the documentation sidebar.

In this topic, # headings specify the start of a section. Each of the contents described above corresponds to a specific section. Here is the format the topic should have:

# Homepage
Welcome to my Documentation!
        
# URLs
[details=Mapping table]
| topic | path |
| -- | -- |
| forum-url/t/general-handbook/5258 | /general-handbook |
| forum-url/t/how-to-install/5256  | /installation |
| forum-url/t/developer-api-specs/5259 | /api |
[/details]

# Navigation
[details=Navigation]
| level | path | navlink |
| -- | -- | -- |
| 1 |  | Handbooks |
| 2 | general-handbook | General Handbook |
| 1 | installation | Installation Instructions |
| 1 | api | Dev API |

[/details]

The names of the sections are important (Homepage, URLs and Navigation).

In the URLs table, we have pairs of topic (forum link) and path (the documentation url path).

In the Navigation table, the level sets the indentation in the sidebar (meaning a level 2 item will be inside the level 1 item immediately above it), path is a path from the URLs table (or empty, if you want a linkless category) and navlink is the actual text in this sidebar navigation item.

Features and Description

Discourse-Docsify will create a blueprint at the /docs url prefix (can be changed through the config) which will serve the files requested by docsify by fetching the forum content for the topic associated with each path.

The original topic markdown is used (and not the discourse html generated output) so you may use any docsify compatible markdown.

A caching feature is also included to speed up loading times (as querying the forum for every request can be quite slow) which may either be through a simple python dictionary or through redis.

Optionally, one function to be run before content is served can also be passed to the Docs object.

The pre_content function

Docs accepts a third parameter: the pre_content function, a function run before each documentation request and that you may use to, for example, restrict access based on some sort of authentication:

def docs_auth_validation(path):
    if 'profile' not in session:
        return redirect('/login')
    if not session['profile']['admin']:
        return abort(403, 'Only admins may view this page.')

docs = Docs(app, {...}, docs_auth_validation)

This function has one argument: the current request's path.

Configuration reference

Setting name Default Description
DOCS_URL_PREFIX /docs The URL prefix for the blueprint that will be serving the docs.
DOCS_HOMEPAGE_TITLE Documentation Homepage title
DOCS_INDEX_PATH There is a default index.html file with a simple docsify example, which you can replace by giving the path to your own file here.
DOCS_TEMPLATE_PATH There is a default template to generate the documentation content (which appends edit buttons with a forum link and last updated time) but you can replace it with your own by entering its path here.
DOCS_HUMANIZE_LOCALE humanize is used to generate the "last updated" strings (2 hours ago, a month ago, etc). If you want to change the language used, enter a locale name here. Example: ru_RU for russian.
DOCS_CACHE_TIMEOUT 60 * 10 Number of seconds for which to cache each page's content.
DOCS_CACHE_TYPE memory either memory (uses a simple python dictionary) or redis
DOCS_CACHE_REDIS_CONN {} if using redis, the redis connection arguments, passed to the Redis constructor.
DOCS_CACHE_REDIS_PREFIX discourse_docsify_docs_ Prefix to use for redis caching
DOCS_DISCOURSE_API_USERNAME Discourse API username. Needed to fetch forum content.
DOCS_DISCOURSE_API_KEY Discourse API key. Needed to fetch forum content.
DOCS_DISCOURSE_BASE_URL The discourse (forum) main url.
DOCS_DISCOURSE_INDEX_TOPIC_ID The ID of the index topic (the number at the end of the topic url).

Metadata

Release files for discourse-docsify 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for discourse-docsify 1.0.2
File Size Uploaded Provenance Actions
discourse-docsify-1.0.2.tar.gz 10.8 kB Without provenance Details for discourse-docsify-1.0.2.tar.gz

Release files / discourse-docsify-1.0.2.tar.gz

Download URL discourse-docsify-1.0.2.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
848d7ce5d3cf1de5adc71f781c85488a51245f10c54db250830d87dd0a83cc2f
BLAKE2b-256 checksum
How to use checksums
4b9ba455096aefaa348365d2278697eab8ce3b40881c75450a870a1c57b2a2ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

Security for discourse-docsify 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.2 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page