diff --git a/README.md b/README.md index 813c836be..28f7ae083 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ * **Many configuration options** — change the color palette, font families, language, icons, favicon and logo. Add a source repository link, links to your - social profiles, Google Analytics and Disqus - all with a few lines of config. + social profiles, and Google Analytics - all with a few lines of config. * **Truly international** — thanks to many contributors, Material for MkDocs includes translations for more than 40 languages and offers full native RTL diff --git a/docs/customization.md b/docs/customization.md index 1b4d11585..14696d872 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -178,7 +178,6 @@ The following template blocks are provided by the theme: | `announce` | Wraps the announcement bar | | `config` | Wraps the JavaScript application config | | `content` | Wraps the main content | -| `disqus` | Wraps the Disqus integration | | `extrahead` | Empty block to add custom meta tags | | `fonts` | Wraps the font definitions | | `footer` | Wraps the footer with navigation and copyright | diff --git a/docs/setup/adding-a-comment-system.md b/docs/setup/adding-a-comment-system.md index 62ba4ecc7..7f1f0b9dd 100644 --- a/docs/setup/adding-a-comment-system.md +++ b/docs/setup/adding-a-comment-system.md @@ -5,104 +5,92 @@ template: overrides/main.html # Adding a comment system Material for MkDocs allows to easily add the third-party comment system of your -choice to the footer of every page by using [theme extension]. As an example, -we'll be integrating [Disqus] a wildly popular comment provider, but others -can be integrate with the same principles +choice to the footer of any page by using [theme extension]. As an example, +we'll be integrating [Giscus], which is Open Source, free, and uses GitHub +discussions as a backend. - [Disqus]: https://disqus.com/ + [Giscus]: https://giscus.app/ ## Customization -### Disqus integration +### Giscus integration -In order to integrate a third-party comment provider offering a JavaScript-based -solution, follow the guide on [theme extension], copy the contents from the -[`content.html`][content partial] partial and create a file at the same location -in the `overrides` folder: +Before you can use [Giscus], you need to complete the following steps: -=== ":octicons-file-code-16: overrides/partials/content.html" +1. __Install the [Giscus GitHub App]__ and grant access to the repository + that should host comments as GitHub discussions. Note that this can be a + repository different from your documentation. +2. __Visit [Giscus] and generate the snippet__ through their configuration tool + to load the comment system. Copy the snippet for the next step. The + resulting snippet should look similar to this: ``` html - - - - {% set disqus = config.extra.disqus %} - {% if page and page.meta and page.meta.disqus is string %} - {% set disqus = page.meta.disqus %} - {% endif %} - - - {% if not page.is_homepage and disqus %} -

{{ lang.t("meta.comments") }}

-
- - {% endif %} + ``` - 1. Ensure you've set [`site_url`][site_url] in `mkdocs.yml`. +You can either integrate [Giscus] on every page by overriding the `main.html` +template, or create a new template (e.g. `blog.html`) to extend from `main.html` +which includes the comment system, so you can decide for each page whether you +want to allow comments or not. -=== ":octicons-file-code-16: mkdocs.yml" +In order to integrate [Giscus], follow the guide on [theme extension] and +[override the `content` block][overriding blocks], extending the default by +calling the `super()` function at the beginning of the block: - ``` yaml - extra: - disqus: # (1)! - ``` +``` html hl_lines="6" +{% block content %} + {{ super() }} - 1. Add your Disqus [shortname] here. + +

{{ lang.t("meta.comments") }}

+ + + +{% endblock %} +``` + +1. This code block ensures that [Giscus] renders with a dark theme when the + palette is set to `slate`. Note that multiple dark themes are available, + so you can change it to your liking. + +Replace the highlighted line with the snippet you generated with the [Giscus] +configuration tool in the previous step. If you extended `main.html`, you should +now see the [Giscus] comment system at the bottom of each page. If you created +a new, separate template, you can enable Giscus by [setting the page template] +via front matter. + + [Giscus GitHub App]: https://github.com/apps/giscus [theme extension]: ../customization.md#extending-the-theme - [content partial]: https://github.com/squidfunk/mkdocs-material/blob/master/src/partials/content.html - [shortname]: https://help.disqus.com/en/articles/1717111-what-s-a-shortname - -#### on a single page - -When [Metadata] is enabled, Disqus can be enabled or disabled for a single page -with custom front matter. Add the following lines at the top of a Markdown file: - -=== ":octicons-check-circle-fill-16: Enabled" - - ``` bash - --- - disqus: - --- - - # Document title - ... - ``` - -=== ":octicons-skip-16: Disabled" - - ``` bash - --- - disqus: "" - --- - - # Document title - ... - ``` - - [Metadata]: extensions/python-markdown.md#metadata + [overriding blocks]: ../customization.md#overriding-blocks + [setting the page template]: ../reference/index.md#setting-the-page-template