git.s-ol.nu mmm / a032d74
fix server-side CORS HTTP requests s-ol 1 year, 11 months ago
2 changed file(s) with 28 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
77 cost: 0.5
88 transform: (url) =>
99 id = assert (url\match '//dl%.acm%.org/citation%.cfm%?id=(%d+)'), "couldn't parse cite/acm URL: '#{url}'"
10 "https://cors-anywhere.herokuapp.com/https://dl.acm.org/exportformats.cfm?id=#{id}&expformat=bibtex"
10 uri = "https://dl.acm.org/downformats.cfm?id=#{id}&parent_id=&expformat=bibtex"
11 if MODE == 'CLIENT'
12 "https://cors-anywhere.herokuapp.com/#{uri}"
13 else
14 uri
1115 }
1216 {
1317 inp: 'text/bibtex'
1923 for key, val in kv\gmatch '([a-z]-)%s*=%s*{(.-)}'
2024 info[key] = val
2125
22 div "#{info.author} (#{info.year}),", (i info.title), ". #{info.publisher}"
26 div "#{info.author} (#{info.year}), ", (i info.title), ". #{info.publisher}"
2327 }
2428 }
2529 }
1616 loadwith = (_load) -> (val, fileder, key) =>
1717 func = assert _load val, "#{fileder}##{key}"
1818 func!
19
20 string.yieldable_gsub = (str, pat, f) ->
21 -- escape percent signs
22 str = str\gsub '%%', '%%|'
23
24 matches = {}
25 str\gsub pat, (...) ->
26 table.insert matches, { ... }
27 "%#{#matches}"
28
29 for match in *matches
30 match.replacement = f table.unpack match
31
32 str\gsub '%%(%d+)', (i) -> matches[i].replacement
33
34 -- unescape escaped percent signs
35 str\gsub '%%|', '%%'
1936
2037 -- list of converts, editors
2138 -- converts each have
5875 cost: 0.1
5976 transform: if MODE == 'SERVER'
6077 (html, fileder) =>
61 html = html\gsub '<mmm%-link%s+(.-)>(.-)</mmm%-link>', (attrs, text) ->
78 html = html\yieldable_gsub '<mmm%-link%s+(.-)>(.-)</mmm%-link>', (attrs, text) ->
6279 text = nil if #text == 0
6380 path = ''
6481 while attrs and attrs != ''
7592
7693 link_to path, text, fileder
7794
78 html = html\gsub '<mmm%-embed%s+(.-)>(.-)</mmm%-embed>', (attrs, desc) ->
95 html = html\yieldable_gsub '<mmm%-embed%s+(.-)>(.-)</mmm%-embed>', (attrs, desc) ->
7996 path, facet = '', ''
8097 opts = {}
8198 if #desc != 0
136153 out: '%1',
137154 cost: 1
138155 transform: (source, fileder) =>
139 source\gsub '{{(.-)}}', (expr) ->
156 source\yieldable_gsub '{{(.-)}}', (expr) ->
140157 path, facet = expr\match '^([%w%-_%./]*)%+(.*)'
141158 assert path, "couldn't match TPL expression '#{expr}'"
142159
200217 (uri) =>
201218 request = require 'http.request'
202219 req = request.new_from_uri uri
203 headers, stream = req\go 8
220 req.headers\upsert 'origin', 'null'
221 headers, stream = assert req\go 8
204222 assert stream\get_body_as_string!
205223 }
206224 {