mirror of
https://git.sr.ht/~edwardloveall/scribe
synced 2025-12-10 12:41:23 +00:00
Handle gists with file extensions
Somehow, in my Gist Proxy code 7518a035b1 I never accounted for gist
ids with file extensions. For example: `def123.js` instead of plain
`def123`. This is now fixed and articles with those kinds of gists in
them work now.
Reference article:
https://medium.com/neat-tips-tricks/ocaml-continuation-explained-3b73839
b679f
This commit is contained in:
@@ -9,20 +9,15 @@ class GistParams
|
||||
|
||||
def self.extract_from_url(href : String)
|
||||
uri = URI.parse(href)
|
||||
maybe_id = Monads::Try(Regex::MatchData)
|
||||
.new(->{ uri.path.match(GIST_ID_REGEX) })
|
||||
.to_maybe
|
||||
.fmap(->(matches : Regex::MatchData) { matches[0] })
|
||||
case maybe_id
|
||||
in Monads::Just
|
||||
id = maybe_id.value!
|
||||
in Monads::Nothing, Monads::Maybe
|
||||
maybe_id = Path.posix(uri.path).stem
|
||||
|
||||
if maybe_id.matches?(GIST_ID_REGEX)
|
||||
id = maybe_id
|
||||
filename = uri.query_params["file"]?
|
||||
new(id: id, filename: filename)
|
||||
else
|
||||
raise MissingGistId.new(href)
|
||||
end
|
||||
|
||||
filename = uri.query_params["file"]?
|
||||
|
||||
new(id: id, filename: filename)
|
||||
end
|
||||
|
||||
def initialize(@id : String, @filename : String?)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module Scribe
|
||||
VERSION = "2022-03-12"
|
||||
VERSION = "2022-04-04"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user