Skip to content

Commit

Permalink
Updated for custom plugin for deep linking
Browse files Browse the repository at this point in the history
  • Loading branch information
quinthar committed Sep 25, 2024
1 parent 2b4f0d2 commit 808d5a9
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
6 changes: 6 additions & 0 deletions help/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ source "https://rubygems.org"
# This will help ensure the proper Jekyll version is running.
# Happy Jekylling!
gem "jekyll", "~> 4.3.4"

# This is the default theme for new Jekyll sites. You may change this to anything you like.
gem "minima", "~> 2.5"

# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
# uncomment the line below. To upgrade, run `bundle update github-pages`.
# gem "github-pages", group: :jekyll_plugins
Expand All @@ -31,3 +33,7 @@ gem "wdm", "~> 0.1", :platforms => [:mingw, :x64_mingw, :mswin]
# Lock `http_parser.rb` gem to `v0.6.x` on JRuby builds since newer versions of the gem
# do not have a Java counterpart.
gem "http_parser.rb", "~> 0.6.0", :platforms => [:jruby]

# For HTML editing
gem "nokogiri"

20 changes: 19 additions & 1 deletion help/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,30 @@ GEM
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
mercenary (0.4.0)
mini_portile2 (2.8.7)
minima (2.5.2)
jekyll (>= 3.5, < 5.0)
jekyll-feed (~> 0.9)
jekyll-seo-tag (~> 2.1)
nokogiri (1.16.7)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.16.7-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.7-arm-linux)
racc (~> 1.4)
nokogiri (1.16.7-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86-linux)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4)
pathutil (0.16.2)
forwardable-extended (~> 2.6)
public_suffix (6.0.1)
racc (1.8.1)
rake (13.2.1)
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
Expand Down Expand Up @@ -138,7 +155,7 @@ GEM
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
unicode-display_width (2.6.0)
webrick (1.8.1)
webrick (1.8.2)

PLATFORMS
aarch64-linux
Expand Down Expand Up @@ -174,6 +191,7 @@ DEPENDENCIES
jekyll (~> 4.3.4)
jekyll-feed (~> 0.12)
minima (~> 2.5)
nokogiri
tzinfo (>= 1, < 3)
tzinfo-data
wdm (~> 0.1)
Expand Down
59 changes: 59 additions & 0 deletions help/_plugins/51_HeaderIDPostRender.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require 'nokogiri'
require 'cgi' # Use CGI for URL encoding

module Jekyll
class HeaderIDPostRender
# Hook into Jekyll's post_render stage to ensure we work with the final HTML
Jekyll::Hooks.register :pages, :post_render, priority: 51 do |page|
process_page(page)
end

Jekyll::Hooks.register :documents, :post_render, priority: 51 do |post|
process_page(post)
end

def self.process_page(page)
return unless page.output_ext == ".html" # Only apply to HTML pages
return if page.output.nil? # Skip if no output has been generated

puts " Processing page: #{page.path}"

# Parse the page's content for header elements
doc = Nokogiri::HTML(page.output)
h1_id = ""
h2_id = ""
h3_id = ""

# Process all <h2>, <h3>, and <h4> elements
(2..4).each do |level|
doc.css("h#{level}").each do |header|
header_text = header.text.strip.downcase
header_id = CGI.escape(header_text.gsub(/\s+/, '-').gsub(/[^\w\-]/, ''))

puts " Found h#{level}: '#{header_text}' -> ID: '#{header_id}'"

# Create hierarchical IDs by appending to the parent header IDs
if level == 2
h2_id = header_id
header['id'] = h2_id
elsif level == 3
h3_id = "#{h2_id}:#{header_id}"
header['id'] = h3_id
elsif level == 4
h4_id = "#{h3_id}:#{header_id}"
header['id'] = h4_id
end

puts " Assigned ID: #{header['id']}"
end
end

# Log the final output being written
puts " Writing updated HTML for page: #{page.path}"

# Write the updated HTML back to the page
page.output = doc.to_html
end
end
end

1 change: 0 additions & 1 deletion help/superapp.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
layout: product
title: Expensify Superapp
---
# Expensify Superapp

## Introduction
The Expensify Superapp packs the full power of 6 world class business, finance, and collaboration products, into a single app that works identically on desktop and mobile, efficiently with your colleagues, and seamlessly with your customers, vendors, family, and friends.
Expand Down

0 comments on commit 808d5a9

Please sign in to comment.