extras/autoindex.rb in yahns-1.16.0 vs extras/autoindex.rb in yahns-1.17.0
- old
+ new
@@ -12,10 +12,25 @@
# all bikeshedding here :>
class Autoindex
FN = %{<a href="%s">%s</a>}
TFMT = "%Y-%m-%d %H:%M"
+ # default to a dark, web-safe (216 color) palette for power-savings.
+ # Color-capable browsers can respect the prefers-color-scheme:light
+ # @media query (browser support a work-in-progress)
+ STYLE = <<''.gsub(/^\s*/m, '').delete!("\n")
+@media screen {
+ *{background:#000;color:#ccc}
+ a{color:#69f;text-decoration:none}
+ a:visited{color:#96f}
+}
+@media screen AND (prefers-color-scheme:light) {
+ *{background:#fff;color:#333}
+ a{color:#00f;text-decoration:none}
+ a:visited{color:#808}
+}
+
def initialize(app, *args)
app.respond_to?(:root) or raise ArgumentError,
"wrapped app #{app.inspect} does not respond to #root"
@app = app
@root = app.root
@@ -137,11 +152,12 @@
files.sort! { |(a,_),(b)| a <=> b }.map! { |(_,ent)| ent }
path_info_html = path_info_ue.split(%r{/}, -1).map! do |part|
Rack::Utils.escape_html(part)
end.join("/")
- body = "<html><head><title>Index of #{path_info_html}</title></head>" \
- "<body><h1>Index of #{path_info_html}</h1><hr><pre>\n" \
+ body = "<html><head><title>Index of #{path_info_html}</title>" \
+ "<style>#{STYLE}</style>" \
+ "</head><body><h1>Index of #{path_info_html}</h1><hr><pre>\n" \
"#{dirs.concat(files).join("\n")}" \
"</pre><hr></body></html>\n"
h = { "Content-Type" => "text/html", "Content-Length" => body.size.to_s }
[ 200, h, [ body ] ]
else