Randomly shuffle donation links on final page

This commit is contained in:
TEC 2022-10-17 00:08:55 +08:00
parent 5cf1046c8d
commit 1cfc57a584
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
4 changed files with 93 additions and 67 deletions

View File

@ -2,7 +2,7 @@
julia_version = "1.8.2"
manifest_format = "2.0"
project_hash = "7fa9bc39e3ae741288470877e398ff9f29579821"
project_hash = "c29e8447aeee171858dde0b54605eebd985a214b"
[[deps.ArgParse]]
deps = ["Logging", "TextWrap"]

View File

@ -12,6 +12,7 @@ HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
Inflector = "6d011eab-0732-4556-8808-e463c76bf3b6"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SQLite = "0aa819cd-b072-5ff4-a722-6bc24af294d9"
SearchLight = "340e8cb6-72eb-11e8-37ce-c97ebeb32050"
SearchLightSQLite = "21a827c4-482a-11ea-3a19-4d2243a4a2c5"

View File

@ -1,6 +1,7 @@
module SurveysController
using Genie.Router, Genie.Requests, Genie.Renderers.Html, HTTP
using Random # For shuffling donation links
using ..Main.UserApp.Results, ..Main.UserApp.Surveys, Dates
@ -50,7 +51,8 @@ function completed(uid)
preserve_query = false))
end
res = html(:surveys, :thanks, layout=:base;
uid=uidstr, survey=SURVEY, resultlinks=links)
uid=uidstr, survey=SURVEY, resultlinks=links,
donateitems=donationlinks())
Genie.Cookies.set!(res, "response-page", 0, Dict{String, Any}("maxage" => -1))
Genie.Cookies.set!(res, "response-id", "", Dict{String, Any}("maxage" => -1))
end
@ -174,4 +176,91 @@ function submit(forminfo::Dict; backpage::Bool=false)
end
end
const DONATION_INDIVIDUALS = [
("https://liberapay.com/hlissner/",
"Henrik Lissner", "hlissner",
["Doom Emacs" => "doomemacs/doomemacs", "assorted packages"]),
("https://liberapay.com/magit/",
"Jonas Bernoulli", "tarsius",
["Magit" => "magit", "Transient" => "transient", "others"]),
("https://github.com/sponsors/abo-abo",
"Oleh Krehel", "abo-abo",
["Swiper" => "swiper", "Hydra" => "hydra",
"Avy" => "avy", "Lispy" => "Lispy"]),
("https://github.com/sponsors/progfolio",
"Nicholas Vollmer", "progfolio",
["Straight" => "radian-software/straight.el",
"Elpaca" => "elpaca", "Doct" => "doct"]),
("https://liberapay.com/protesilaos/",
"Protesilaos Stavrou", "protesilaos",
["Modus themes" => "https://git.sr.ht/~protesilaos/modus-themes",
"Denote" => "https://git.sr.ht/~protesilaos/denote",
"others"]),
("https://github.com/sponsors/yyoncho",
"Ivan Yonchovski", "yyoncho",
["lsp-mode" => "emacs-lsp/lsp-mode", "dap-mode" => "emacs-lisp/dap-mode",
"and other LSP things"]),
("https://liberapay.com/wasamasa/",
"Vasilij Schneidermann", "wasamasa",
["nov.el" => "https://depp.brause.cc/nov.el/",
"circe" => "https://github.com/emacs-circe/circe",
"eyebrowse" => "https://depp.brause.cc/eyebrowse",
"shackle" => "https://depp.brause.cc/shackle"]),
("https://liberapay.com/tec",
"me, Timothy", "tecosaur",
["this survey", "a few other things"])
]
function donationlinks()
donate_org = ("https://liberapay.com/org-mode/",
"The Org Project",
"https://orgmode.org",
["org-mode" => "https://orgmode.org"])
donate_fsf = ("https://my.fsf.org/donate",
"The Free Software Foundation",
"https://www.fsf.org/",
["an assortment of projects"])
donate_specs = vcat(donate_org,
shuffle(DONATION_INDIVIDUALS),
donate_fsf)
donate_spec_to_link.(donate_specs)
end
function donate_spec_to_link((link, name, site, projects))
string("<li><a href=\"$link\"><b>Donate to</b></a> ",
name, ' ',
if isnothing(site)
""
elseif occursin("http", site)
"<a href=\"$site\" target=\"_blank\" title=\"Homepage\" \
style=\"color: var(--secondary); display: inline-block; \
transform: scale(-1, 1)\">⎋</a>"
else # assume GitHub username
"<a href=\"https://github.com/$site\" target=\"_blank\" \
style=\"color: var(--secondary)\" \
title=\"GitHub profile\">@$site</a>"
end,
" (responsible for ",
join(map(projects) do proj
if proj isa String
proj
elseif proj isa Pair{String,String}
string("<a href=\"",
if occursin("http", proj[2])
proj[2]
elseif occursin("/", proj[2])
"https://github.com/$(proj[2])"
elseif !isnothing(site)
"https://github.com/$site/$(proj[2])"
end,
"\" target=\"_blank\" title=\"Project page\" \
style=\"color: var(--h1-color)\">",
proj[1], "</a>")
else
""
end
end, ", ", ", and "),
")</li>")
end
end

View File

@ -24,71 +24,7 @@
<p>Should this sound like something you would be interested in, here
is a small selection of donation links that may be of interest.</p>
<ul>
<%
let donations = [
("https://liberapay.com/org-mode/",
"The Org Project", nothing,
["org-mode" => "https://orgmode.org"]),
("https://liberapay.com/hlissner/",
"Henrik Lissner", "hlissner",
["Doom Emacs" => "doomemacs/doomemacs", "assorted packages"]),
("https://liberapay.com/magit/",
"Jonas Bernoulli", "tarsius",
["Magit" => "magit", "Transient" => "transient", "others"]),
("https://github.com/sponsors/abo-abo",
"Oleh Krehel", "abo-abo",
["Swiper" => "swiper", "Hydra" => "hydra",
"Avy" => "avy", "Lispy" => "Lispy"]),
("https://github.com/sponsors/progfolio",
"Nicholas Vollmer", "progfolio",
["Straight" => "radian-software/straight.el",
"Elpaca" => "elpaca", "Doct" => "doct"]),
("https://liberapay.com/protesilaos/",
"Protesilaos Stavrou", "protesilaos",
["Modus themes" => "https://git.sr.ht/~protesilaos/modus-themes",
"Denote" => "https://git.sr.ht/~protesilaos/denote",
"others"]),
("https://github.com/sponsors/yyoncho",
"Ivan Yonchovski", "yyoncho",
["lsp-mode" => "emacs-lsp/lsp-mode", "dap-mode" => "emacs-lisp/dap-mode",
"and other LSP things"]),
("https://liberapay.com/wasamasa/",
"Vasilij Schneidermann", "wasamasa",
["nov.el" => "https://depp.brause.cc/nov.el/",
"circe" => "https://github.com/emacs-circe/circe",
"eyebrowse" => "https://depp.brause.cc/eyebrowse",
"shackle" => "https://depp.brause.cc/shackle"]),
("https://my.fsf.org/donate",
"The Free Software Foundation", nothing,
["an assortment of projects"]),
];
map(donations) do (link, name, github, projects)
string("<li><a href=\"$link\"><b>Donate to</b></a> ",
name, ' ',
if !isnothing(github)
"<a href=\"https://github.com/$github\" style=\"color: var(--secondary)\">@$github</a>"
else "" end,
" (responsible for ",
join(map(projects) do proj
if proj isa String
proj
elseif proj isa Pair{String, String}
string("<a href=\"",
if occursin("http", proj[2])
proj[2]
elseif occursin("/", proj[2])
"https://github.com/$(proj[2])"
elseif !isnothing(github)
"https://github.com/$github/$(proj[2])"
end,
"\" style=\"color: var(--h1-color)\">",
proj[1], "</a>")
else "" end
end, ", ", ", and "),
")</li>")
end |> lines -> join(lines, '\n')
end
%>
$(join(donateitems, '\n'))
</ul>
<br />
<a href="/" role="button">Go Home</a>