mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
- Admin → About shows the running version's release notes, with a link to all releases. - The What's new page keeps the running version (and any newer) open and folds each older release to one line, grouped by month: its version and a count of its changes, fixes and notes for administrators. - CHANGELOG.md itself is unchanged and reads the same on GitHub; the app splits it into releases when shown (Changelog). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
44 lines
2.0 KiB
Ruby
44 lines
2.0 KiB
Ruby
# The user guide: Markdown files in docs/guide (readable on GitHub too),
|
|
# shown in the app under /help. Only the pages listed here can be opened.
|
|
class HelpGuide
|
|
DIR = Rails.root.join("docs/guide")
|
|
ORDER = %w[README getting-started profile aircraft flights squawks oil-and-fuel components logbook records
|
|
inspections ads documents major-records sharing administration api disclaimer changelog].freeze
|
|
OPTIONS = {
|
|
parse: { smart: true },
|
|
render: { hardbreaks: false, unsafe: false },
|
|
extension: { strikethrough: true, tagfilter: true, table: true, autolink: true, header_ids: "" }
|
|
}.freeze
|
|
TAGS = %w[p br strong em del a ul ol li blockquote code pre h1 h2 h3 h4 hr table thead tbody tr th td].freeze
|
|
ATTRIBUTES = %w[href id align].freeze
|
|
|
|
Page = Data.define(:slug, :title, :markdown)
|
|
|
|
def self.pages = ORDER.filter_map { find(_1) }
|
|
|
|
def self.find(slug)
|
|
return unless ORDER.include?(slug.to_s)
|
|
path = slug.to_s == "changelog" ? Rails.root.join("CHANGELOG.md") : DIR.join("#{slug}.md")
|
|
return unless path.file?
|
|
markdown = path.read
|
|
Page.new(slug: slug.to_s, title: markdown[/\A# (.+)$/, 1] || slug.to_s.titleize, markdown: markdown)
|
|
end
|
|
|
|
# Sanitized HTML. Links to other guide pages ("records.md#mistakes") go
|
|
# through `link` (slug, anchor) -> URL, or become plain text when nil.
|
|
def self.html(page, link:, title: true)
|
|
render(title ? page.markdown : page.markdown.sub(/\A# .+\n+/, ""), link: link)
|
|
end
|
|
|
|
# Any Markdown from the guide (or a part of it, such as one release of the changelog).
|
|
def self.render(source, link:)
|
|
html = Commonmarker.to_html(source, options: OPTIONS, plugins: { syntax_highlighter: nil })
|
|
html = Rails::HTML5::SafeListSanitizer.new.sanitize(html, tags: TAGS, attributes: ATTRIBUTES)
|
|
html.gsub(%r{<a href="([a-z-]+|README)\.md(?:#([a-z0-9-]+))?">(.*?)</a>}m) do
|
|
slug, anchor, text = $1, $2, $3
|
|
next text unless link && ORDER.include?(slug)
|
|
%(<a href="#{ERB::Util.h(link.call(slug, anchor))}">#{text}</a>)
|
|
end
|
|
end
|
|
end
|