From e0aed95739530a6eea12ccdd7fec37d359bc3788 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sat, 6 Sep 2025 22:09:23 +0200 Subject: [PATCH] Remove the old TeX migration scripts --- bin/migrate.rb | 42 --------- bin/split.rb | 229 ------------------------------------------------- 2 files changed, 271 deletions(-) delete mode 100755 bin/migrate.rb delete mode 100755 bin/split.rb diff --git a/bin/migrate.rb b/bin/migrate.rb deleted file mode 100755 index 968b3b0..0000000 --- a/bin/migrate.rb +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env ruby - -require 'pg' - -connection = PG.connect(user: 'caraus', dbname: 'caraus_blog') -query = <<~SQL -SELECT articles.*, categories.name -FROM articles -INNER JOIN categories on categories.id = articles.category_id -SQL -connection.exec query do |result| - result.each do |row| - post_contents = <<~POST - --- - layout: post - POST - - date = row['created_at'].gsub /\.[[:digit:]]+$/, '' - post_contents << "date: #{date}\n" - if row['name'] == 'Über Technik und Philosophie' - category = 'Aufsatz' - else - category = row['name'] - end - post_contents << "tags: #{category}\n" - - if row['title'].include? '"' - post_contents << "title: |\n #{row['title']}\n" - else - post_contents << "title: #{row['title']}\n" - end - - post_contents << "teaser:\n #{row['teaser']}\n" unless row['teaser'].nil? - post_contents << "---\n" - post_contents << "#{row['description'].delete("\r")}\n" - - post_path = (Pathname.new('themes/posts') + row['slug']).sub_ext('.html') - - post_path.dirname.mkpath - post_path.write post_contents - end -end diff --git a/bin/split.rb b/bin/split.rb deleted file mode 100755 index b5dbf94..0000000 --- a/bin/split.rb +++ /dev/null @@ -1,229 +0,0 @@ -#!/usr/bin/env ruby - -require 'open3' - -OUTPUT_FILE = 'var/tmp.txt' - -def handle_line(line, output) - if line.length < 120 || line.start_with?("\t") - output << line - else - in_tag = false - last_whitespace = 0 - - for line_position in 0...line.length - current_character = line[line_position] - - if line_position == line.length.pred - output << line - elsif current_character == ' ' && !in_tag - if line_position > 80 && last_whitespace > 0 - output << line[0...line_position] - handle_line line[line_position.succ..], output - return - else - last_whitespace = line_position - end - else - case current_character - when '<' - in_tag = true - when '>' - in_tag = false - end - end - end - end -end - -def split(source) - output_lines = [] - - source.each_line do |line| - handle_line line.chomp, output_lines - end - - output_lines.join "\n" -end - -def diff(source, transformed_text) - File.write(OUTPUT_FILE, transformed_text.gsub(' ', "\n") + "\n") - - Open3.popen2 'diff', '-Nur', OUTPUT_FILE, '-' do |stdin, stdout, wait_thr| - stdin.puts source.gsub(' ', "\n") - stdin.close - - print stdout.read - - wait_thr.value - end - transformed_text -end - -def head(source) - source.lines.map do |line| - next line unless line.start_with?('\n") - - header_text = line[4...-6].gsub /^\d\. /, '' - header_level = line[2].to_i - - case header_level - when 2 - "\\section{#{header_text}}\n" - when 3 - "\\subsection{#{header_text}}\n" - when 4 - "\\subsubsection{#{header_text}}\n" - else - line - end - end.join -end - -def references(source) - references_start = '
    ' - references_index = source.index(references_start) - return source if references_index.nil? - - replaced = source[0...references_index] - references_text = source[references_index + references_start.length + 1...-('
'.length + 1)] - - references_text.each_line do |line| - reference_id, reference_text = line.strip.delete_prefix('
  • ') - puts "#{reference_id}: #{reference_text}" - - reference_match = source.match(/(\d+)<\/a><\/sup>/) - if reference_match - answer = STDIN.gets - - if answer.nil? - File.write OUTPUT_FILE, replaced - return replaced - else - reference_name, page = answer.chomp.split(' ', 2) - - see = '[Vgl.]' if reference_text.start_with? 'Vgl.' - replaced.sub!(reference_match[0], "\\footcite#{see}[#{page}]{#{reference_name}}") - end - else - puts 'No match!' - end - end - - File.write OUTPUT_FILE, replaced - replaced -end - -def quotes(source) - paragraphs = source.split("\n\n") - - paragraphs.each do |paragraph| - last_index = 0 - quote_indices = [] - quote_pair = [] - - while true - last_index = paragraph.index('"', last_index + 1) - if last_index.nil? - break - elsif quote_pair.empty? - quote_pair << last_index - else - quote_pair << last_index - quote_indices << quote_pair - quote_pair = [] - end - end - if quote_pair.empty? - quote_indices.each do |first_quote, second_quote| - paragraph[first_quote] = '„' - paragraph[second_quote] = '“' - end - end - end - - paragraphs.join("\n\n") -end - -def print_out(source) - print source - source -end - -def break_lines(source) - source.gsub('

    \n\n/, %{\n\n
      }) - .sub('
    ', "\n") - .gsub('