Last active
November 10, 2025 11:08
Convert a GitHub Wiki to static HTML files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'fileutils' | |
| require 'pathname' | |
| require 'commonmarker' | |
| require 'github/markup' | |
| require 'gollum-lib' | |
| wiki_dir = '.' | |
| out_dir = "#{wiki_dir}/out" | |
| HTML_TEMPLATE = <<~HTML | |
| <!DOCTYPE html> | |
| <html lang="mul"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="color-scheme" content="light dark"> | |
| <meta name="format-detection" content="telephone=no"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>%{title} - Wikinder</title> | |
| <link rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/"> | |
| <link | |
| rel="stylesheet" | |
| href="https://cdn.jsdelivr.net/npm/katex@0.16.25/dist/katex.min.css" | |
| integrity="sha384-WcoG4HRXMzYzfCgiyfrySxx90XSl2rxY5mnVY5TwtWE6KLrArNKn0T/mOgNL0Mmi" | |
| crossorigin="anonymous" | |
| > | |
| <script | |
| defer | |
| src="https://cdn.jsdelivr.net/npm/katex@0.16.25/dist/katex.min.js" | |
| integrity="sha384-J+9dG2KMoiR9hqcFao0IBLwxt6zpcyN68IgwzsCSkbreXUjmNVRhPFTssqdSGjwQ" | |
| crossorigin="anonymous" | |
| ></script> | |
| <script | |
| defer | |
| src="https://cdn.jsdelivr.net/npm/katex@0.16.25/dist/contrib/auto-render.min.js" | |
| integrity="sha384-hCXGrW6PitJEwbkoStFjeJxv+fSOOQKOPbJxSfM6G5sWZjAyWhXiTIIAmQqnlLlh" | |
| crossorigin="anonymous" | |
| ></script> | |
| <script> | |
| document.addEventListener('DOMContentLoaded', () => { | |
| renderMathInElement(document.body, { | |
| delimiters: [ | |
| { left: '$$', right: '$$', display: true }, | |
| { left: '$', right: '$', display: false }, | |
| ], | |
| }); | |
| }); | |
| </script> | |
| </head> | |
| <body> | |
| <h1>%{title}</h1> | |
| %{content} | |
| </body> | |
| </html> | |
| HTML | |
| # https://github.com/gollum/gollum/wiki/Custom-rendering-gems | |
| GitHub::Markup::Markdown::MARKDOWN_GEMS['commonmarker'] = proc do |content| | |
| Commonmarker.to_html(content, options: { | |
| render: { unsafe: true }, | |
| extension: { | |
| strikethrough: true, | |
| tagfilter: true, | |
| table: true, | |
| autolink: true, | |
| tasklist: true, | |
| }, | |
| }) | |
| end | |
| GitHub::Markup::Markdown::MARKDOWN_GEMS.delete('kramdown') | |
| wiki = Gollum::Wiki.new(wiki_dir, base_path: '/') | |
| FileUtils.mkdir_p(out_dir) | |
| wiki.pages.each do |page| | |
| path = Pathname.new(page.path) | |
| html = HTML_TEMPLATE % { | |
| title: page.name.gsub('-', ' '), | |
| path: path.sub_ext(''), | |
| content: page.formatted_data, | |
| } | |
| html_file = File.join(out_dir, path.sub_ext('.html')) | |
| File.write(html_file, html) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment