mirror of https://github.com/freeCodeCamp/devdocs
parent
9a5b70c066
commit
018d09cc6d
@ -0,0 +1,32 @@
|
|||||||
|
module Docs
|
||||||
|
class Hammerspoon
|
||||||
|
class CleanHtmlFilter < Filter
|
||||||
|
def call
|
||||||
|
|
||||||
|
# Remove script tags for functionality not needed in DevDocs
|
||||||
|
css("script").remove
|
||||||
|
|
||||||
|
# Remove styles that are not necessary
|
||||||
|
css("style").remove
|
||||||
|
|
||||||
|
# Modify the main title - remove leading "docs » "
|
||||||
|
at_css("h1").content = at_css("h1").content.sub("docs » ", "")
|
||||||
|
|
||||||
|
# add syntax highlighting
|
||||||
|
css("pre").each do |pre|
|
||||||
|
if pre.get_attribute("lang") == "lua"
|
||||||
|
pre.set_attribute("data-language", "lua")
|
||||||
|
pre.remove_attribute("lang")
|
||||||
|
else
|
||||||
|
if pre.get_attribute("lang")
|
||||||
|
# logger.warn("unrecognised pre.get_attribute('lang') = #{pre.get_attribute("lang")}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
doc
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,71 @@
|
|||||||
|
module Docs
|
||||||
|
class Hammerspoon
|
||||||
|
class EntriesFilter < Docs::EntriesFilter
|
||||||
|
def get_name
|
||||||
|
at_css("h1").content
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_type
|
||||||
|
subpath.split("/")[0]
|
||||||
|
end
|
||||||
|
|
||||||
|
def additional_entries
|
||||||
|
return [] if root_page?
|
||||||
|
entries = []
|
||||||
|
|
||||||
|
base_name = at_css("h1").content
|
||||||
|
|
||||||
|
# add a base entry
|
||||||
|
entries << [base_name, nil, base_name]
|
||||||
|
|
||||||
|
css("section").each do |section|
|
||||||
|
title_node = section.at_css("h5")
|
||||||
|
if title_node.nil?
|
||||||
|
next
|
||||||
|
end
|
||||||
|
entry_name = title_node.content.strip
|
||||||
|
entry_id = section["id"]
|
||||||
|
|
||||||
|
fn_type = section.at_css("a.dashAnchor").get_attribute("name")
|
||||||
|
# this dashAnchor is the most consistent way to get the type of the entry
|
||||||
|
if fn_type.start_with?("//apple_ref/cpp/Function")
|
||||||
|
fn_type = "Function"
|
||||||
|
entry_name << "()"
|
||||||
|
elsif fn_type.start_with?("//apple_ref/cpp/Constructor/")
|
||||||
|
fn_type = "Constructor"
|
||||||
|
entry_name << "()"
|
||||||
|
elsif fn_type.start_with?("//apple_ref/cpp/Method")
|
||||||
|
fn_type = "Method"
|
||||||
|
entry_name << "()"
|
||||||
|
elsif fn_type.start_with?("//apple_ref/cpp/Class")
|
||||||
|
fn_type = "Class"
|
||||||
|
elsif fn_type.start_with?("//apple_ref/cpp/Constant")
|
||||||
|
fn_type = "Constant"
|
||||||
|
elsif fn_type.start_with?("//apple_ref/cpp/Variable")
|
||||||
|
fn_type = "Variable"
|
||||||
|
elsif fn_type.start_with?("//apple_ref/cpp/Deprecated")
|
||||||
|
fn_type = "Deprecated"
|
||||||
|
elsif fn_type.start_with?("//apple_ref/cpp/Field")
|
||||||
|
fn_type = "Field"
|
||||||
|
else
|
||||||
|
fn_type = "Unknown"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Create a new entry for each method/function
|
||||||
|
if fn_type != "Unknown"
|
||||||
|
entries << ["#{base_name}.#{entry_name}", entry_id, base_name]
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
entries
|
||||||
|
end
|
||||||
|
|
||||||
|
def include_default_entry?
|
||||||
|
# Decide when to include the default entry
|
||||||
|
# Here we include it unless the page is a module overview or similar
|
||||||
|
!subpath.end_with?("index.lp")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,32 @@
|
|||||||
|
module Docs
|
||||||
|
class Hammerspoon < UrlScraper
|
||||||
|
self.type = 'hammerspoon'
|
||||||
|
self.root_path = ''
|
||||||
|
self.links = {
|
||||||
|
home: 'https://www.hammerspoon.org',
|
||||||
|
code: 'https://github.com/Hammerspoon/hammerspoon'
|
||||||
|
}
|
||||||
|
|
||||||
|
html_filters.push 'hammerspoon/clean_html', 'hammerspoon/entries'
|
||||||
|
|
||||||
|
# links with no content will still render a page, this is an error in the docs
|
||||||
|
# (see: https://github.com/Hammerspoon/hammerspoon/pull/3579)
|
||||||
|
options[:skip] = ['module.lp/matrix.md']
|
||||||
|
# Replace '/module.lp/' with '' in URLs
|
||||||
|
options[:replace_paths] = { 'localhost:12345/module.lp/MATRIX.md' => 'localhost:12345/module.lp/hs.canvas.matrix' }
|
||||||
|
|
||||||
|
# Hammerspoon docs don't have a license (MIT specified in the hammerspoon repo)
|
||||||
|
# https://github.com/Hammerspoon/hammerspoon/blob/master/LICENSE
|
||||||
|
options[:attribution] = <<-HTML
|
||||||
|
Hammerspoon
|
||||||
|
HTML
|
||||||
|
|
||||||
|
|
||||||
|
version '0.9.100' do
|
||||||
|
self.release = '0.9.100'
|
||||||
|
# add `hs.doc.hsdocs.start()` to your init.lua to enable the docs server
|
||||||
|
self.base_url = 'http://localhost:12345/'
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
After Width: | Height: | Size: 901 B |
After Width: | Height: | Size: 1.4 KiB |
@ -0,0 +1 @@
|
|||||||
|
https://www.hammerspoon.org/images/hammerspoon.ico
|
Loading…
Reference in new issue