Skip to content

Commit

Permalink
add archive.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
hejohns committed Jul 2, 2024
1 parent bd2d585 commit 35fcfa8
Show file tree
Hide file tree
Showing 86 changed files with 20,742 additions and 35,471 deletions.
168 changes: 168 additions & 0 deletions _plugins/include_absolute.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
module Jekyll
module Tags
class IncludeAbsoluteTagError < StandardError
attr_accessor :path

def initialize(msg, path)
super(msg)
@path = path
end
end

class IncludeAbsoluteTag < Liquid::Tag
VALID_SYNTAX = %r!
([\w-]+)\s*=\s*
(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+))
!x
VARIABLE_SYNTAX = %r!
(?<variable>[^{]*(\{\{\s*[\w\-\.]+\s*(\|.*)?\}\}[^\s{}]*)+)
(?<params>.*)
!mx

FULL_VALID_SYNTAX = %r!\A\s*(?:#{VALID_SYNTAX}(?=\s|\z)\s*)*\z!
VALID_FILENAME_CHARS = %r!^[\w/\.-]+$!

def initialize(tag_name, markup, tokens)
super
matched = markup.strip.match(VARIABLE_SYNTAX)
if matched
@file = matched["variable"].strip
@params = matched["params"].strip
else
@file, @params = markup.strip.split(%r!\s+!, 2)
end
validate_params if @params
@tag_name = tag_name
end

def syntax_example
"{% #{@tag_name} 'file.ext' param='value' param2='value' %}"
end

def parse_params(context)
params = {}
markup = @params

while (match = VALID_SYNTAX.match(markup))
markup = markup[match.end(0)..-1]

value = if match[2]
match[2].gsub(%r!\\"!, '"')
elsif match[3]
match[3].gsub(%r!\\'!, "'")
elsif match[4]
context[match[4]]
end

params[match[1]] = value
end
params
end

def validate_file_name(file)
if file !~ VALID_FILENAME_CHARS
raise ArgumentError, <<-MSG
Invalid syntax for include tag. File contains invalid characters or sequences:
#{file}
Valid syntax:
#{syntax_example}
MSG
end
end

def validate_params
unless @params =~ FULL_VALID_SYNTAX
raise ArgumentError, <<-MSG
Invalid syntax for include tag:
#{@params}
Valid syntax:
#{syntax_example}
MSG
end
end

# Grab file read opts in the context
def file_read_opts(context)
context.registers[:site].file_read_opts
end

# Render the variable if required
def render_variable(context)
if @file =~ VARIABLE_SYNTAX
partial = context.registers[:site]
.liquid_renderer
.file("(variable)")
.parse(@file)
partial.render!(context)
end
end

def render(context)
site = context.registers[:site]

file = render_variable(context) || @file
# strip leading and trailing quote's
file = file.gsub!(/\A'|'\Z/, '')
validate_file_name(file)

source = File.expand_path(context.registers[:site].config['source']).freeze
path = File.join(source, file)
return unless path

partial = Liquid::Template.parse(read_file(path, context))

context.stack do
context["include"] = parse_params(context) if @params
begin
partial.render!(context)
rescue Liquid::Error => e
e.template_name = path
e.markup_context = "included " if e.markup_context.nil?
raise e
end
end
end

def valid_include_file?(path, dir, safe)
!outside_site_source?(path, dir, safe) && File.file?(path)
end

def outside_site_source?(path, dir, safe)
safe && !realpath_prefixed_with?(path, dir)
end

def realpath_prefixed_with?(path, dir)
File.exist?(path) && File.realpath(path).start_with?(dir)
rescue StandardError
false
end

# This method allows to modify the file content by inheriting from the class.
def read_file(file, context)
File.read(file, **file_read_opts(context))
end

private

def could_not_locate_message(file, includes_dirs, safe)
message = "Could not locate the included file '#{file}' in any of "\
"#{includes_dirs}. Ensure it exists in one of those directories and"
message + if safe
" is not a symlink as those are not allowed in safe mode."
else
", if it is a symlink, does not point outside your site source."
end
end
end
end
end

Liquid::Template.register_tag("include_absolute", Jekyll::Tags::IncludeAbsoluteTag)
6 changes: 6 additions & 0 deletions _posts/archiving-stack-overflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ some reason the stack overflow MathJax initially loads fine, then disappears
with "math processing error".

Yeah… not the way I wanted this to go but I think this second version works.

```
{% include_absolute '_forest/archive.rb' %}
```
4 changes: 2 additions & 2 deletions _site/2023/04/09/gsi-applications.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ <h2 id="engr-101-f23">ENGR 101 (F23)</h2>

<iframe width="560" height="315" src="https://www.youtube.com/embed/Cd9Tq7s_BhQ" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen=""></iframe>

<style> .pdf-embed-wrap-c6b07f7a-3cd5-4207-9550-83fd90f7ac56 { display: flex; flex-direction: column; width: 100%; height: 650px; } .pdf-embed-container-c6b07f7a-3cd5-4207-9550-83fd90f7ac56 { height: 100%; } .pdf-link-c6b07f7a-3cd5-4207-9550-83fd90f7ac56 { background-color: white; text-align: center; border-style: solid; } .pdf-embed-container-c6b07f7a-3cd5-4207-9550-83fd90f7ac56 iframe { width: 100%; height: 100%; } </style>
<div class="pdf-embed-wrap-c6b07f7a-3cd5-4207-9550-83fd90f7ac56"> <div class="pdf-link-c6b07f7a-3cd5-4207-9550-83fd90f7ac56"> <a href="/files/101-gsi-application.pdf" target="_blank">View PDF</a> </div> <div class="pdf-embed-container-c6b07f7a-3cd5-4207-9550-83fd90f7ac56"> <iframe src="/files/101-gsi-application.pdf" frameborder="0" allowfullscreen=""></iframe> </div> </div>
<style> .pdf-embed-wrap-a4cb3c96-5442-49fa-b0ad-d6a59776b24c { display: flex; flex-direction: column; width: 100%; height: 650px; } .pdf-embed-container-a4cb3c96-5442-49fa-b0ad-d6a59776b24c { height: 100%; } .pdf-link-a4cb3c96-5442-49fa-b0ad-d6a59776b24c { background-color: white; text-align: center; border-style: solid; } .pdf-embed-container-a4cb3c96-5442-49fa-b0ad-d6a59776b24c iframe { width: 100%; height: 100%; } </style>
<div class="pdf-embed-wrap-a4cb3c96-5442-49fa-b0ad-d6a59776b24c"> <div class="pdf-link-a4cb3c96-5442-49fa-b0ad-d6a59776b24c"> <a href="/files/101-gsi-application.pdf" target="_blank">View PDF</a> </div> <div class="pdf-embed-container-a4cb3c96-5442-49fa-b0ad-d6a59776b24c"> <iframe src="/files/101-gsi-application.pdf" frameborder="0" allowfullscreen=""></iframe> </div> </div>
<h2 id="eecs-376-f23">EECS 376 (F23)</h2>
<p><strong>outcome</strong>: rejected. No response.</p>
<h3 id="too-long-version">too long version</h3>
Expand Down
2 changes: 1 addition & 1 deletion _site/2023/08/03/nic-bonding.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ <h1 class="post-title p-name" itemprop="name headline">nic bonding</h1>
<div class="footer-col"><a href="/2023/07/24/book-catalogue.html">prev</a></div>
<div class="footer-col">
<h2> related </h2>
<ul><li><a href="/2023/04/23/scripting.html">some remarks apropos scripting,</a></li><li><a href="/2023/12/20/xmonad.html">xmonad,</a></li><li><a href="/2023/10/10/tortoise-tts.html">tortoise text to speech (and piper),</a></li><li><a href="/2024/03/10/deoplete.html">deoplete,</a></li><li><a href="/2024/02/08/natural-models.html">Natural Models,</a></li><li><a href="/site-construction/2023/05/14/darcs.html">moving from git to darcs,</a></li><li><a href="/site-construction/2023/04/05/page-sorting.html">sorting the page links in the top right header,</a></li><li><a href="/2024/04/11/fountain-pen-nibs.html">fountain pen nibs,</a></li><li><a href="/2024/01/08/thunderbird-and-nix.html">Thunderbird and Nix,</a></li><li><a href="/2023/05/10/linux-graphics-modules.html">multiple displays and linux graphics modules,</a></li><li><a href="/2023/12/19/icecc.html">icecc,</a></li></ul>
<ul><li><a href="/2023/04/23/scripting.html">some remarks apropos scripting,</a></li><li><a href="/2023/12/20/xmonad.html">xmonad,</a></li><li><a href="/2023/10/10/tortoise-tts.html">tortoise text to speech (and piper),</a></li><li><a href="/2024/03/10/deoplete.html">deoplete,</a></li><li><a href="/2024/02/08/natural-models.html">Natural Models,</a></li><li><a href="/site-construction/2023/05/14/darcs.html">moving from git to darcs,</a></li><li><a href="/2024/04/11/fountain-pen-nibs.html">fountain pen nibs,</a></li><li><a href="/site-construction/2023/04/05/page-sorting.html">sorting the page links in the top right header,</a></li><li><a href="/2024/01/08/thunderbird-and-nix.html">Thunderbird and Nix,</a></li><li><a href="/2023/05/10/linux-graphics-modules.html">multiple displays and linux graphics modules,</a></li><li><a href="/2023/12/19/icecc.html">icecc,</a></li></ul>
</div>
<div class="footer-col"><a href="/2023/10/10/tortoise-tts.html">next</a></div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion _site/2023/12/19/icecc.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ <h1 class="post-title p-name" itemprop="name headline">icecc</h1>
<div class="footer-col"><a href="/2023/11/07/ble-sh.html">prev</a></div>
<div class="footer-col">
<h2> related </h2>
<ul><li><a href="/2023/10/10/tortoise-tts.html">tortoise text to speech (and piper),</a></li><li><a href="/2023/12/20/xmonad.html">xmonad,</a></li><li><a href="/2023/04/23/scripting.html">some remarks apropos scripting,</a></li><li><a href="/2024/03/10/deoplete.html">deoplete,</a></li><li><a href="/2023/05/10/linux-graphics-modules.html">multiple displays and linux graphics modules,</a></li><li><a href="/2024/02/08/natural-models.html">Natural Models,</a></li><li><a href="/2024/04/11/fountain-pen-nibs.html">fountain pen nibs,</a></li><li><a href="/2024/02/24/vim.html">vim,</a></li><li><a href="/2024/06/17/archiving-stack-overflow.html">archiving stack overflow (for the forest),</a></li><li><a href="/2024/01/08/thunderbird-and-nix.html">Thunderbird and Nix,</a></li><li><a href="/site-construction/2023/04/05/welcome-to-jekyll.html">Welcome to Jekyll!,</a></li></ul>
<ul><li><a href="/2023/10/10/tortoise-tts.html">tortoise text to speech (and piper),</a></li><li><a href="/2023/12/20/xmonad.html">xmonad,</a></li><li><a href="/2023/04/23/scripting.html">some remarks apropos scripting,</a></li><li><a href="/2024/03/10/deoplete.html">deoplete,</a></li><li><a href="/2023/05/10/linux-graphics-modules.html">multiple displays and linux graphics modules,</a></li><li><a href="/2024/02/08/natural-models.html">Natural Models,</a></li><li><a href="/2024/04/11/fountain-pen-nibs.html">fountain pen nibs,</a></li><li><a href="/2024/02/24/vim.html">vim,</a></li><li><a href="/2024/01/08/thunderbird-and-nix.html">Thunderbird and Nix,</a></li><li><a href="/2024/06/17/archiving-stack-overflow.html">archiving stack overflow (for the forest),</a></li><li><a href="/site-construction/2023/04/05/welcome-to-jekyll.html">Welcome to Jekyll!,</a></li></ul>
</div>
<div class="footer-col"><a href="/2023/12/20/xmonad.html">next</a></div>
</div>
Expand Down
35 changes: 35 additions & 0 deletions _site/2024/06/17/archiving-stack-overflow.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,41 @@ <h2 id="second-iteration">Second Iteration</h2>

<p>Yeah… not the way I wanted this to go but I think this second version works.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
#!/usr/bin/env ruby

require 'selenium-webdriver'

driver = Selenium::WebDriver.for :firefox
driver.get(ARGV[0])

# https://meta.stackoverflow.com/questions/268400/is-there-a-get-query-string-to-expand-all-comments-by-default#comment555104_268456
sleep 1
driver.execute_script(
"javascript:for(x of document.getElementsByClassName('js-add-link comments-link'))x.click()"
)

# We get MathJax rendering errors for some reason, so let's just use the
# browser's "Save Page As"
#puts driver.page_source

# For some reason, the selenium action for C-s doesn't work, but things like
# C-a, tab, S-tab, work
# Not that it matters much, since we wouldn't be able to interact with the
# popup anyways
#driver.action.key_down(:control).key_down('s').key_up(:control).key_up('s').perform

# somehow, we always come back to xdotool...
`xdotool key ctrl+s`
system('xdotool', 'type', File.expand_path(ARGV[1]))
`xdotool key alt+s`

sleep 1
driver.quit


</code></pre></div></div>

</div><!-- use minima's column styling since I don't know css -->
<div class="footer-col-wrapper">
<div class="footer-col"><a href="/2024/04/11/fountain-pen-nibs.html">prev</a></div>
Expand Down
39 changes: 37 additions & 2 deletions _site/feed.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.3.3">Jekyll</generator><link href="https://hejohns.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://hejohns.github.io/" rel="alternate" type="text/html" /><updated>2024-07-02T03:34:02-04:00</updated><id>https://hejohns.github.io/feed.xml</id><title type="html">hejohns’ jekyll site</title><subtitle>a pure waste of space</subtitle><author><name>Johnson He</name><email>hejohns α umich δ edu</email></author><entry><title type="html">archiving stack overflow (for the forest)</title><link href="https://hejohns.github.io/2024/06/17/archiving-stack-overflow.html" rel="alternate" type="text/html" title="archiving stack overflow (for the forest)" /><published>2024-06-17T00:00:00-04:00</published><updated>2024-06-29T04:03:08-04:00</updated><id>https://hejohns.github.io/2024/06/17/archiving-stack-overflow</id><content type="html" xml:base="https://hejohns.github.io/2024/06/17/archiving-stack-overflow.html"><![CDATA[<h2 id="first-iteration">First Iteration</h2>
<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.3.3">Jekyll</generator><link href="https://hejohns.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://hejohns.github.io/" rel="alternate" type="text/html" /><updated>2024-07-02T03:47:03-04:00</updated><id>https://hejohns.github.io/feed.xml</id><title type="html">hejohns’ jekyll site</title><subtitle>a pure waste of space</subtitle><author><name>Johnson He</name><email>hejohns α umich δ edu</email></author><entry><title type="html">archiving stack overflow (for the forest)</title><link href="https://hejohns.github.io/2024/06/17/archiving-stack-overflow.html" rel="alternate" type="text/html" title="archiving stack overflow (for the forest)" /><published>2024-06-17T00:00:00-04:00</published><updated>2024-06-29T04:03:08-04:00</updated><id>https://hejohns.github.io/2024/06/17/archiving-stack-overflow</id><content type="html" xml:base="https://hejohns.github.io/2024/06/17/archiving-stack-overflow.html"><![CDATA[<h2 id="first-iteration">First Iteration</h2>

<p>(Note: I call any stack exchange site “stack overflow”.)</p>

Expand Down Expand Up @@ -48,7 +48,42 @@ then save the page with Firefox’s “Save Page As…”, scripted with <code c
some reason the stack overflow MathJax initially loads fine, then disappears
with “math processing error”.</p>

<p>Yeah… not the way I wanted this to go but I think this second version works.</p>]]></content><author><name>Johnson He</name><email>hejohns α umich δ edu</email></author><summary type="html"><![CDATA[First Iteration]]></summary></entry><entry><title type="html">fountain pen nibs</title><link href="https://hejohns.github.io/2024/04/11/fountain-pen-nibs.html" rel="alternate" type="text/html" title="fountain pen nibs" /><published>2024-04-11T00:00:00-04:00</published><updated>2024-04-11T17:48:22-04:00</updated><id>https://hejohns.github.io/2024/04/11/fountain-pen-nibs</id><content type="html" xml:base="https://hejohns.github.io/2024/04/11/fountain-pen-nibs.html"><![CDATA[<p>Several weeks ago, I lost my other TWSBI 580 (technically, the 580 ALR)
<p>Yeah… not the way I wanted this to go but I think this second version works.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
#!/usr/bin/env ruby

require 'selenium-webdriver'

driver = Selenium::WebDriver.for :firefox
driver.get(ARGV[0])

# https://meta.stackoverflow.com/questions/268400/is-there-a-get-query-string-to-expand-all-comments-by-default#comment555104_268456
sleep 1
driver.execute_script(
"javascript:for(x of document.getElementsByClassName('js-add-link comments-link'))x.click()"
)

# We get MathJax rendering errors for some reason, so let's just use the
# browser's "Save Page As"
#puts driver.page_source

# For some reason, the selenium action for C-s doesn't work, but things like
# C-a, tab, S-tab, work
# Not that it matters much, since we wouldn't be able to interact with the
# popup anyways
#driver.action.key_down(:control).key_down('s').key_up(:control).key_up('s').perform

# somehow, we always come back to xdotool...
`xdotool key ctrl+s`
system('xdotool', 'type', File.expand_path(ARGV[1]))
`xdotool key alt+s`

sleep 1
driver.quit


</code></pre></div></div>]]></content><author><name>Johnson He</name><email>hejohns α umich δ edu</email></author><summary type="html"><![CDATA[First Iteration]]></summary></entry><entry><title type="html">fountain pen nibs</title><link href="https://hejohns.github.io/2024/04/11/fountain-pen-nibs.html" rel="alternate" type="text/html" title="fountain pen nibs" /><published>2024-04-11T00:00:00-04:00</published><updated>2024-04-11T17:48:22-04:00</updated><id>https://hejohns.github.io/2024/04/11/fountain-pen-nibs</id><content type="html" xml:base="https://hejohns.github.io/2024/04/11/fountain-pen-nibs.html"><![CDATA[<p>Several weeks ago, I lost my other TWSBI 580 (technically, the 580 ALR)
which meant that I didn’t have any EF nibs left<sup id="fnref:1" role="doc-noteref"><a href="#fn:1" class="footnote" rel="footnote">1</a></sup>.</p>
<p>Through the process of sourcing nibs, I learned a lot about the details so:</p>
Expand Down
Loading

0 comments on commit 35fcfa8

Please sign in to comment.