module Asciidoctor::Html::Template
def self.appendix_title(chapname, numeral, doctitle, num_appendices)
def self.appendix_title(chapname, numeral, doctitle, num_appendices) numeral = num_appendices == 1 ? "" : " #{numeral}" %(<span class="title-prefix">#{chapname}#{numeral}</span>#{doctitle}) end
def self.footer(authors)
def self.footer(authors) <<~HTML <footer class="footer"> <div class="footer-left">© <span id="cr-year"></span> #{authors}</div> <div class="footer-right">Built with <a href="https://github.com/ravirajani/asciidoctor-html">asciidoctor-html</a> </div> </footer> HTML end
def self.head(title, description, authors, langs)
def self.head(title, description, authors, langs) <<~HTML <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> #{%(<meta name="description" content="#{description}">) if description} #{%(<meta name="author" content="#{authors}">) if authors} <title>#{title}</title> <link rel="apple-touch-icon" sizes="180x180" href="#{FAVICON_PATH}/apple-touch-icon.png"> <link rel="icon" type="image/png" sizes="32x32" href="#{FAVICON_PATH}/favicon-32x32.png"> <link rel="icon" type="image/png" sizes="16x16" href="#{FAVICON_PATH}/favicon-16x16.png"> <link rel="manifest" href="#{FAVICON_PATH}/site.webmanifest" crossorigin="anonymous"> <link rel="stylesheet" href="#{CSS_PATH}/styles.css"> <link rel="stylesheet" href="#{Highlightjs::CDN_PATH}/styles/tomorrow-night-blue.min.css"> <script defer src="#{Highlightjs::CDN_PATH}/highlight.min.js"></script> #{highlightjs langs} <script> MathJax = { tex: { inlineMath: {'[+]': [['$', '$']]} }, output: { displayOverflow: 'linebreak' } }; </script> <script defer src="https://cdn.jsdelivr.net/npm/mathjax@4/tex-chtml.js"></script> <script defer src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/js/bootstrap.bundle.min.js" integrity="sha384-j1CDi7MgGQ12Z7Qab0qlWQ/Qqz24Gc6BM0thvEMVjHnfYGF0rmFCozFSxQBxwHKO" crossorigin="anonymous"></script> HTML end
def self.header(title, short_title)
def self.header(title, short_title) <<~HTML <header class="header"> <a class="home d-none d-sm-block" href="./">#{title}</a> <a class="home d-block d-sm-none" href="./">#{short_title}</a> </header> HTML end
def self.highlightjs(langs)
def self.highlightjs(langs) langs.map do |lang| %(<script defer src="#{Highlightjs::CDN_PATH}/languages/#{lang}.min.js"></script>) end.join("\n ") end
def self.html(content, nav_items, opts = {})
- at_head_end: String
- langs: Array[String]
- chapsubheading: String
- chapheading: String
- description: String
- authors: String
- short_title: String
- title: String
opts:
def self.html(content, nav_items, opts = {}) nav = (nav_items.size > 1) <<~HTML <!DOCTYPE html> <html lang="en"> <head> #{head opts[:title], opts[:description], opts[:authors], opts[:langs]} #{opts[:at_head_end]} </head> <body> #{sidebar(nav_items) if nav} <div id="page" class="page"> #{MENU_BTN if nav} #{header opts[:title], opts[:short_title]} #{main content:, **opts} </div> <!-- .page --> <script>document.getElementById("cr-year").textContent = (new Date()).getFullYear();</script> <script type="module"> #{Highlightjs::PLUGIN} #{Popovers::POPOVERS} #{Sidebar::TOGGLE if nav} #{Scroll::SCROLL} </script> #{opts[:at_body_end]} </body> </html> HTML end
def self.main(opts)
- authors: String
- content: String
- chapsubheading: String
- chapheading: String
opts:
def self.main(opts) <<~HTML <main id="main" class="main"> <div id="content-container" class="content-container"> #{%(<h1 class="chapheading">#{opts[:chapheading]}</h1>) if opts[:chapheading]} <h1 class="chaptitle">#{opts[:chapsubheading]}</h1> #{opts[:content]} #{footer opts[:authors]} </div> </main> HTML end
def self.nav_item(target, text, content = "", active: false)
def self.nav_item(target, text, content = "", active: false) active_class = active ? %( class="active") : "" link = %(<a href="#{target}">#{text}</a>) subnav = content.empty? ? content : "\n#{content}\n" %(<li#{active_class}>#{link}#{subnav}</li>\n) end
def self.nav_text(chapprefix, chaptitle)
def self.nav_text(chapprefix, chaptitle) return chaptitle if chapprefix.empty? %(<div class="nav-mark">#{chapprefix}</div>#{chaptitle}) end
def self.sidebar(nav_items)
def self.sidebar(nav_items) <<~HTML <div id="sidebar" class="sidebar"> <button id="sidebar-dismiss-btn" class="btn dismiss"><i class="bi bi-x-lg"></i></button> <nav><ul> #{nav_items.join "\n"} </ul></nav> </div> <!-- .sidebar --> HTML end
def self.sitemap(entries)
def self.sitemap(entries) <<~XML <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> #{entries.join "\n"} </urlset> XML end
def self.sitemap_entry(url)
def self.sitemap_entry(url) <<~XML <url> <loc>#{url}</loc> </url> XML end