diff options
author | EuAndreh <eu@euandre.org> | 2024-11-17 20:15:02 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-11-17 20:18:21 -0300 |
commit | cfd0246b241cb6e58153e68f7e30ed56b9bf054b (patch) | |
tree | 206deba2cec12187e835c64b8a7172277be1a2cf /_plugins | |
parent | rm tests/assert-frontmatter.sh (diff) | |
download | euandre.org-cfd0246b241cb6e58153e68f7e30ed56b9bf054b.tar.gz euandre.org-cfd0246b241cb6e58153e68f7e30ed56b9bf054b.tar.xz |
Remove jekyll infrastructure setup
Diffstat (limited to '_plugins')
-rw-r--r-- | _plugins/add-anchor-to-code-block-line-numbers.rb | 20 | ||||
-rw-r--r-- | _plugins/add-anchor-to-header-from-header-id.rb | 11 | ||||
-rw-r--r-- | _plugins/add-link-to-plaintext-code-block.rb | 13 | ||||
-rw-r--r-- | _plugins/generate-feeds-for-categories.rb | 74 | ||||
-rw-r--r-- | _plugins/generate-media-permalink.rb | 61 | ||||
-rw-r--r-- | _plugins/generate-pastebin-plaintext-alternate.rb | 44 | ||||
-rw-r--r-- | _plugins/graphviz-block.rb | 36 | ||||
-rw-r--r-- | _plugins/has-category-filter.rb | 13 | ||||
-rw-r--r-- | _plugins/linter.rb | 219 | ||||
-rw-r--r-- | _plugins/noop-converter.rb | 18 |
10 files changed, 0 insertions, 509 deletions
diff --git a/_plugins/add-anchor-to-code-block-line-numbers.rb b/_plugins/add-anchor-to-code-block-line-numbers.rb deleted file mode 100644 index ec6f0a8..0000000 --- a/_plugins/add-anchor-to-code-block-line-numbers.rb +++ /dev/null @@ -1,20 +0,0 @@ -PREFIX = '<pre class="lineno">' -POSTFIX = '</pre>' -Jekyll::Hooks.register [:documents, :pages], :post_render do |doc| - if doc.output_ext == ".html" && doc.type != :slides - code_block_counter = 1 - doc.output = doc.output.gsub(/<pre class="lineno">[\n0-9]+<\/pre>/) do |match| - line_numbers = match - .gsub(/<pre class="lineno">([\n0-9]+)<\/pre>/, '\1') - .split("\n") - - anchored_line_numbers_array = line_numbers.map do |n| - id = "B#{code_block_counter}-L#{n}" - "<a class=\"code-line-anchor\" id=\"#{id}\" href=\"##{id}\">#{n}</a>" - end - code_block_counter += 1 - - PREFIX + anchored_line_numbers_array.join("\n") + POSTFIX - end - end -end diff --git a/_plugins/add-anchor-to-header-from-header-id.rb b/_plugins/add-anchor-to-header-from-header-id.rb deleted file mode 100644 index 7138262..0000000 --- a/_plugins/add-anchor-to-header-from-header-id.rb +++ /dev/null @@ -1,11 +0,0 @@ -Jekyll::Hooks.register [:documents, :pages], :post_render do |doc| - if doc.output_ext == ".html" && doc.type != :slides - lang = doc.data["lang"] - alt = doc.site.site_payload["site"]["t"]["alt"]["link_icon"][lang] - doc.output = - doc.output.gsub( - /<h([1-6])(.*?)id="([\w-]+)"(.*?)>(.*?)<\/h[1-6]>/, - '<div class="header-anchor"><h\1\2id="\3"\4>\5</h\1><a href="#\3"><img class="simple-icon" src="/static/link.svg" aria-hidden="true" alt="' + alt + '" /></a></div>' - ) - end -end diff --git a/_plugins/add-link-to-plaintext-code-block.rb b/_plugins/add-link-to-plaintext-code-block.rb deleted file mode 100644 index 34b4ce7..0000000 --- a/_plugins/add-link-to-plaintext-code-block.rb +++ /dev/null @@ -1,13 +0,0 @@ -Jekyll::Hooks.register :documents, :post_render do |doc| - if doc.output_ext == ".html" && doc.type != :slides - code_block_counter = 0 - doc.output = doc.output.gsub(/(<\/code><\/pre><\/div><\/div>)/) do |match| - res = match + - '<div class="plaintext-link"><a href="' + - "#{doc.url}.#{code_block_counter}.txt" + - '">plaintext</a></div>' - code_block_counter += 1 - res - end - end -end diff --git a/_plugins/generate-feeds-for-categories.rb b/_plugins/generate-feeds-for-categories.rb deleted file mode 100644 index 870f86f..0000000 --- a/_plugins/generate-feeds-for-categories.rb +++ /dev/null @@ -1,74 +0,0 @@ -module Jekyll - class FeedsGenerator < Generator - safe true - - def gen_categories_index(site) - categories_index = {} - site.collections.each do |collection| - collection_name, collection_documents = collection - collection_documents.docs.each do |document| - lang = document.data["lang"] - categories = document.data["eu_categories"] - if categories != nil - categories.split(",").each do |category| - categories_index[collection_name] ||= {} - categories_index[collection_name][lang] ||= {} - categories_index[collection_name][lang][category] ||= [] - - categories_index[collection_name][lang][category] << document - end - end - end - end - categories_index - end - - def feeds_by_category(site) - feed_pages = [] - gen_categories_index(site).each do |collection_name, langs| - langs.each do |lang, categories| - categories.each do |category_name, articles| - category = category_name.gsub(/ /, '-') - feed_name = "feed.#{collection_name}-by-category.#{lang}.#{category}.atom" - page = PageWithoutAFile.new(site, site.source, "", feed_name) - page.content = <<-EOF -{% include feed.atom entries=site.#{collection_name} kind="#{collection_name}" lang="#{lang}" categories_filter="#{category_name}" %} - EOF - feed_pages << page - end - end - end - feed_pages - end - - def global_feeds(site) - feed_pages = [] - langs = site.config['langs'] - collections = site.config['collections'].keys - langs.each do |lang| - collections.each do |collection| - feed_name = "feed.#{collection}.#{lang}.atom" - page = PageWithoutAFile.new(site, site.source, "", feed_name) - page.content = <<-EOF -{% include feed.atom entries=site.#{collection} kind="#{collection}" lang="#{lang}" %} - EOF - feed_pages << page - end - end - feed_pages - end - - def generate(site) - site.pages.concat(feeds_by_category(site)) - site.pages.concat(global_feeds(site)) - end - end - - class PageWithoutAFile < Jekyll::Page - def read_yaml(*) - @data ||= { - "generated" => true - } - end - end -end diff --git a/_plugins/generate-media-permalink.rb b/_plugins/generate-media-permalink.rb deleted file mode 100644 index ae635bd..0000000 --- a/_plugins/generate-media-permalink.rb +++ /dev/null @@ -1,61 +0,0 @@ -module Jekyll - class MediaPermalinkGenerator < Generator - safe true - - MEDIA_EXTENSION = { - 'podcasts' => 'ogg', - 'screencasts' => 'webm' - } - - def generate(site) - site.collections.each do |name, collection| - if ['podcasts', 'screencasts'].include? name then - collection.docs.each do |document| - date = document.data['date'].strftime('%Y-%m-%d') - slug = document.data['slug'] - extension = MEDIA_EXTENSION[name] - file = "#{date}-#{slug}.#{extension}" - media = "resources/#{name}/#{file}" - torrent = "#{media}.torrent" - media_link = document.url.gsub(/html$/, extension) - torrent_link = "#{media_link}.torrent" - media_page = GeneratedSymlinkResourcePage.new(site, site.source, '', media_link) - torrent_page = GeneratedSymlinkResourcePage.new(site, site.source, '', torrent_link) - media_page.data['source'] = media - media_page.data['slug'] = slug - media_page.data['extension'] = extension - torrent_page.data['source'] = torrent - torrent_page.data['slug'] = slug - torrent_page.data['extension'] = "#{extension}.torrent" - site.pages << media_page - site.pages << torrent_page - end - end - end - end - end - - class GeneratedSymlinkResourcePage < Jekyll::Page - def read_yaml(*) - @data ||= { - "generated" => true - } - end - - def write(dest) - source = @data['source'] - slug = @data['slug'] - extension = @data['extension'] - path = destination(dest) - path_dirname = File.dirname(path) - FileUtils.mkdir_p(path_dirname) - stdout = `ln -fs ../../../../#{source} #{path_dirname}/#{slug}.#{extension}` - unless $?.success? then - raise "Error when running 'ln' command: #{$?}" - end - unless stdout == '' then - raise "Unexpected output of 'ln': #{stdout}" - end - end - end -end diff --git a/_plugins/generate-pastebin-plaintext-alternate.rb b/_plugins/generate-pastebin-plaintext-alternate.rb deleted file mode 100644 index e4e798e..0000000 --- a/_plugins/generate-pastebin-plaintext-alternate.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'cgi' -CODE_BLOCK = /<td class="rouge-code"><pre>(.*?)<\/pre><\/td>/m - -module Jekyll - class PlainTextGenerator < Generator - safe true - - def generate(site) - site.collections.each do |collection| - collection_name, collection_documents = collection - if collection_name != "slides" - collection_documents.docs.each do |document| - n = 0 - Renderer - .new(site, document) # create a renderer for the document - .run # generate the HTML string - .scan(CODE_BLOCK) # match all occurrences of regexp - .each do |code_block| # iterate on each match - unhighlighted_code = code_block[0] # regexp only defines 1 match (only 1 parens) - .gsub(/<span class=".*?">(.*?)<\/span>/m, '\1') - content = CGI.unescapeHTML unhighlighted_code - name = "#{document.url}.#{n}.txt" - plain = PlaintextPageWithoutAFile.new(site, site.source, '', name) - plain.content = content - site.pages << plain - n += 1 - end - end - end - end - end - end - - # Taken from: - # https://github.com/jekyll/jekyll-feed/blob/c552b8ef7bd7a4babcfb5aec2b22283a5bc354dd/lib/jekyll-feed/page-without-a-file.rb#L4 - class PlaintextPageWithoutAFile < Jekyll::Page - def read_yaml(*) - @data ||= { - "plaintext" => true, - "generated" => true - } - end - end -end diff --git a/_plugins/graphviz-block.rb b/_plugins/graphviz-block.rb deleted file mode 100644 index a2e32bf..0000000 --- a/_plugins/graphviz-block.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'tempfile' -require 'digest' - -OUTPUT_DIR = '/static/graphviz' - -module Jekyll - class GraphvizBlock < Liquid::Block - def initialize(tag_name, options, tokens) - super - opts_list = options.split('|').map { |s| s.strip } - @name = opts_list[0] - @alt = opts_list[1] - end - - def render(context) - source = super - site = context.registers[:site] - FileUtils.mkdir_p(File.join(site.source, OUTPUT_DIR)) - - filename = "#{@name}-#{Digest::SHA256.hexdigest(source + @alt)}.svg" - site_path = File.join(OUTPUT_DIR, filename) - os_path = File.join(site.source, site_path) - - f = Tempfile.new('graphviz-input') - f.write(source) - f.close - `dot -Tsvg #{f.path} > #{os_path}` - f.unlink - - site.static_files << Jekyll::StaticFile.new(site, site.source, OUTPUT_DIR, filename) - "<img src=\"#{site_path}\" alt=\"#{@alt}\" />" - end - end -end - -Liquid::Template.register_tag('graphviz', Jekyll::GraphvizBlock) diff --git a/_plugins/has-category-filter.rb b/_plugins/has-category-filter.rb deleted file mode 100644 index fee9b0d..0000000 --- a/_plugins/has-category-filter.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Jekyll - module CategoryFilter - def has_category(input, category) - if category - input.select { |entry| entry.data["eu_categories"]&.split(',')&.include? category } - else - input - end - end - end -end - -Liquid::Template.register_filter(Jekyll::CategoryFilter) diff --git a/_plugins/linter.rb b/_plugins/linter.rb deleted file mode 100644 index af81790..0000000 --- a/_plugins/linter.rb +++ /dev/null @@ -1,219 +0,0 @@ -require 'set' - -IGNORED_PAGES = Set['sitemap.xml'] -LANGS = Set['en', 'pt', 'fr', 'eo'] # jp zh es de - -module Jekyll - class Linter < Generator - safe true - priority :high - - def insert_id(name, document) - lang = document.data['lang'] - ref = document.data['ref'] - id = "#{name}:#{lang}:#{ref}" - if @known_ids.include? id then - # raise "Duplicate ID found: '#{id}'" - else - @known_ids.add id - end - end - - def assert_unique_ids(site) - @known_ids = Set[] - all_documents(site) do |collection_name, document| - insert_id collection_name, document - end - end - - def slugify(s) - s.ljust(100) - .gsub(/[()']/, '') - .gsub(/[\W]+/, ' ') - .strip - .gsub(/\s\s+/, '-') - .downcase - .gsub(' ', '-') - .gsub('_', '-') - end - - def assert(value, message) - unless value - raise message - end - value - end - - def assert_field(document, field) - f = document.data[field] - raise "Undefined '#{field}' for #{document.path}" unless f - f - end - - COLLECTION_LAYOUTS = { - 'page' => 'default', - 'slides' => 'slides', - 'articles' => 'post', - 'pastebins' => 'post', - 'tils' => 'post', - 'podcasts' => 'post', - 'screencasts' => 'post' - } - - def assert_frontmatter_fields(name, document) - title = assert_field document, 'title' - lang = assert_field document, 'lang' - ref = assert_field document, 'ref' - layout = assert_field document, 'layout' - date = document.date.strftime('%Y-%m-%d') unless layout == 'default' - slug = layout == 'default' ? ref : assert_field(document, 'slug') - extension = name == 'slides' ? 'slides' : 'md' - - unless LANGS.member? lang - raise "Invalid lang '#{lang}' in #{document.path}" - end - - if COLLECTION_LAYOUTS[name] != layout - raise "Layout mismatch: expected '#{COLLECTION_LAYOUTS[name]}', got '#{layout}' for #{document.path}" - end - - if lang == 'en' - unless ['index', 'root', 'tils'].include? ref - if slugify(title) != ref then - raise "#{ref} isn't a slug of the title.\nref: '#{ref}'\ntitle slug: '#{slugify(title)}'" - end - end - end - - unless layout == 'default' then - path = "_#{name}/#{date}-#{slug}.#{extension}" - unless path == document.relative_path then - raise "date/filename mismatch:\ndate+slug: #{path}\nfilename: #{document.relative_path}" - end - - if lang == 'en' then - unless ref == slug then - # raise "ref/slug mismatch:\nref: #{ref}\nslug: #{slug}" - end - end - end - - if name == 'podcasts' then - flac = "resources/podcasts/#{date}-#{slug}.flac" - unless File.exist? flac then - raise "Missing FLAC file '#{flac}'" - end - end - - if name == 'screencasts' then - webm = "resources/screencasts/#{date}-#{slug}.webm" - unless File.exist? webm then - raise "Missing WebM file '#{webm}'" - end - end - end - - def assert_frontmatter(site) - all_documents(site) do |collection_name, document| - assert_frontmatter_fields collection_name, document - end - end - - MEDIA_EXTENSION = { - 'podcasts' => 'flac', - 'screencasts' => 'webm' - } - - def assert_media_metadata(site) - site.collections.each do |name, collection| - if ['podcasts', 'screencasts'].include? name then - collection.docs.each do |document| - date = document.data['date'].strftime('%Y-%m-%d') - slug = document.data['slug'] - ext = MEDIA_EXTENSION[name] - file = "resources/#{name}/#{date}-#{slug}.#{ext}" - feed_name = site.config['t'][name]['feed']['title'][document.data['lang']] - if name == 'podcasts' - stdout = `metaflac --export-tags-to=- #{file}`.strip.split("\n") - expected = [ - "COMMENTS=#{site.config['url']}/#{file}", - 'ARTIST=EuAndreh', - "DATE=#{date}", - "TITLE=#{document.data['title']}", - "ALBUM=#{feed_name}" - ] - expected.each do |metadata| - unless stdout.include? metadata - tags = expected.join("\n").gsub(/'/, "'\"'\"'") - add_metadata_cmd = "metaflac --remove-all-tags #{file}\nprintf '#{tags}\n' | metaflac --import-tags-from=- #{file}" - check_metadata_cmd = "metaflac --export-tags-to=- #{file}" - raise "Missing metadata entry '#{metadata}' in '#{file}'.\nAdd it with:\n\n" + add_metadata_cmd + "\n\nCheck with:\n #{check_metadata_cmd}" - end - end - - check_cover_cmd = "metaflac #{file} --export-picture-to=- | diff - static/lord-favicon.png" - `#{check_cover_cmd}` - unless $?.success? then - add_cover_cmd = "metaflac --remove-all #{file}\nmetaflac #{file} --import-picture-from=static/lord-favicon.png" - raise "Cover art from '#{file}' doesn't match 'static/lord-favicon.png'.\nFix it with:\n\n#{add_cover_cmd}\n\nCheck with:\n #{check_cover_cmd}" - end - elsif name == 'screencasts' then - stdout = `mediainfo #{file} | awk -F: '/^Movie name/ { print $2 }'`.strip - expected = document.data['title'] + ' - ' + feed_name - unless stdout == expected then - escaped_title = expected.gsub(/'/, "'\"'\"'") - add_metadata_cmd = "mkvpropedit '#{file}' -e info -s title='#{escaped_title}'" - check_metadata_cmd = "mediainfo '#{file}' | grep 'Movie name'" - raise "Missing metadata entry 'title' in '#{file}'.\nAdd it with:\n\n#{add_metadata_cmd}\n\nCheck with:\n #{check_metadata_cmd}" - end - end - end - end - end - end - - def assert_lilypond(site) - site.config['musics'].each do |music| - assert music['title'], "Missing 'title' in #{music}" - assert music['composer'], "Missing 'composer' in #{music}" - ref = assert music['ref'], "Missing 'ref' in #{music}" - ly = "music/#{ref}.ly" - unless File.exist? ly then - raise "Missing '#{ly}' file present in _config.yml." - end - - unless open(ly) { |f| f.include? "\\pointAndClickOff\n" } then - raise "Missing '\\pointAndClickOff' in '#{ly}'" - end - unless open(ly) { |f| f.include? "#(ly:set-option 'embed-source-code #t)\n" } then - raise "Missing '#(ly:set-option 'embed-source-code #t)' in '#{ly}'" - end - end - end - - def generate(site) - assert_unique_ids(site) - assert_frontmatter(site) - assert_media_metadata(site) - assert_lilypond(site) - end - - def all_documents(site) - site.collections.each do |name, collection| - collection.docs.each do |document| - unless document.data['generated'] - yield name, document - end - end - end - - site.pages.each do |page| - unless IGNORED_PAGES.include? page.path - unless page.data['generated'] - yield 'page', page - end - end - end - end - end -end diff --git a/_plugins/noop-converter.rb b/_plugins/noop-converter.rb deleted file mode 100644 index 118d103..0000000 --- a/_plugins/noop-converter.rb +++ /dev/null @@ -1,18 +0,0 @@ -module Jekyll - class NoOpConverter < Converter - safe true - priority :high - - def matches(ext) - ext == '.slides' - end - - def output_ext(ext) - ".html" - end - - def convert(content) - content - end - end -end |