Remove the old scripts

This commit is contained in:
2025-09-06 22:09:23 +02:00
parent 6b59c5beb6
commit 2f6b51a0a9
2 changed files with 0 additions and 271 deletions

View File

@@ -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

View File

@@ -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?('<h') && line.end_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 = '<ol class="footnote">'
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...-('</ol>'.length + 1)]
references_text.each_line do |line|
reference_id, reference_text = line.strip.delete_prefix('<li id="').delete_suffix('</li>').split('">')
puts "#{reference_id}: #{reference_text}"
reference_match = source.match(/<sup><a href="##{reference_id}">(\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('</p> <p', "</p>\n\n<p")
.sub(/\s+<ol class="footnote">/, %{\n\n<ol class="footnote">})
.sub('</ol>', "\n</ol>")
.gsub('<li id=', "\n\t<li id=")
end
class Arguments
attr_accessor :input
def initialize
@operations = Set.new
end
def read_arguments(arguments)
arguments.each do |argument|
handle_argument argument
end
end
def operations
@operations.to_a
end
private
def handle_argument(argument)
if argument.start_with? '--'
add_option argument
else
@operations << argument
end
end
def add_option(option)
name, value = option.delete_prefix('--').split '='
case name
when 'input'
@input = value
end
end
end
arguments = Arguments.new
arguments.read_arguments ARGV
raise 'No input file given with --input=file' if arguments.input.nil?
operations = arguments.operations
source = transformed_text = File.read arguments.input
while operation = operations.shift do
case operation
when 'break'
# Add line breaks between paragraphs.
transformed_text = break_lines transformed_text
when 'split'
# Split long lines, so each line has 80-120 characters if possible.
transformed_text = split transformed_text
when 'diff'
transformed_text = diff source, transformed_text
when 'head'
# Replace HTML headers with LaTeX sections.
transformed_text = head transformed_text
when 'references'
transformed_text = references transformed_text
when 'quotes'
transformed_text = quotes transformed_text
when 'print'
transformed_text = print_out transformed_text
else
raise "Unknown operation #{operation}"
end
end
# puts transformed_text