From d2f26788b739a09faf18a7a2222f456e073d9394 Mon Sep 17 00:00:00 2001 From: Vallabh Date: Mon, 28 Nov 2022 22:13:36 +0530 Subject: [PATCH] Created html and entries filters for wagtail --- lib/docs/filters/wagtail/clean_html.rb | 65 ++++++++++++++++++++++++++ lib/docs/filters/wagtail/entries.rb | 15 ++++++ 2 files changed, 80 insertions(+) create mode 100644 lib/docs/filters/wagtail/clean_html.rb create mode 100644 lib/docs/filters/wagtail/entries.rb diff --git a/lib/docs/filters/wagtail/clean_html.rb b/lib/docs/filters/wagtail/clean_html.rb new file mode 100644 index 00000000..b5b28b53 --- /dev/null +++ b/lib/docs/filters/wagtail/clean_html.rb @@ -0,0 +1,65 @@ +module Docs + class Wagtail + class CleanHtmlFilter < Filter + def call + # footer contains links like about,contact us etc which + # are not needed in documentation so removed + doc.search('footer').each do |footer| + footer.remove + end + + # aside bar contains the search bar and navigation links + # which are not needed + doc.search('aside').each do |aside| + aside.remove + end + + # header contains links which are not needed(see sourch code of Wagtail docs) + doc.search('header').each do |head| + head.remove + end + + # nav bar contains the search bar and navigation links(older versions) + # which are not needed + doc.search('nav.wy-nav-side').each do |nav| + nav.remove + end + + # removing unimportant links(older versions) + doc.search('nav.wy-nav-top').each do |nav| + nav.remove + end + + # removing unimportant links from header of very old versions + doc.search('ul.wy-breadcrumbs').each do |ul| + ul.remove + end + + # removing release notes + doc.search('li.toctree-l1').each do |li| + li.remove if li.to_s.include? 'Release notes' + end + + # removing release notes(older versions) + doc.search('dl').each do |dl| + dl.remove + end + + # removing scripts and style + css('script', 'style', 'link').remove + css('hr').remove + # Make proper table headers + css('td.header').each do |node| + node.name = 'th' + end + + # Remove code highlighting + css('pre').each do |node| + node.content = node.content + end + + doc + end + end + end +end diff --git a/lib/docs/filters/wagtail/entries.rb b/lib/docs/filters/wagtail/entries.rb new file mode 100644 index 00000000..8af4c4c7 --- /dev/null +++ b/lib/docs/filters/wagtail/entries.rb @@ -0,0 +1,15 @@ +module Docs + class Wagtail + class EntriesFilter < Docs::EntriesFilter + def get_name + # removing the pilcrow sign and returning the heading + at_css('h1').content.strip.remove("\u{00b6}") + end + + def get_type + object, method = *slug.split('/') + method ? object : 'Miscellaneous' + end + end + end +end