Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
krinkko committed Nov 15, 2024
2 parents 2bab1b4 + 88e827f commit 7cf202f
Show file tree
Hide file tree
Showing 232 changed files with 17,913 additions and 13,850 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "themes/maverick"]
path = themes/maverick
url = https://github.com/canhtran/maverick.git
[submodule "themes/hugo-theme-stack"]
path = themes/hugo-theme-stack
url = https://github.com/CaiJimmy/hugo-theme-stack/
10 changes: 10 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,13 @@ type = "toc"
[privacy.youtube]
disable = false
privacyEnhanced = true


[comments]
enabled = true
provider = "cactus"

[comments.cactus]
defaultHomeserverUrl = "https://matrix.cactus.chat:8448"
serverName = "cactus.chat"
siteName = "krinkko.github.io"
2 changes: 1 addition & 1 deletion config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ provider = "cactus"
[comments.cactus]
defaultHomeserverUrl = "https://matrix.cactus.chat:8448"
serverName = "cactus.chat"
siteName = "krinkko.github.io"
siteName = "krinkko.github.io"
2 changes: 1 addition & 1 deletion content/categories/Adminkram/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ description: "Sammelsurium an Dingen die Sysadmins so vor die Füße fallen. Bil
slug: "adminkram"
image: "luca-bravo-XJXWbfSo2f0-unsplash.jpg"
style:
background: "#2a9d8f"
background: "#3498db"
color: "#fff"
---
2 changes: 1 addition & 1 deletion content/categories/Fahrradkultur/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ description: "Ich mag Fahrräder mit allem Drum und Dran. Ab und zu findet davon
slug: "fahrradkultur"
image: "DSC_0099.JPG"
style:
background: "#2a9d8f"
background: "#1abc9c"
color: "#fff"
---
2 changes: 1 addition & 1 deletion content/categories/Gardening/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ description: "Wir haben einen Kleingarten. Folgt uns bei unseren Abendteuern."
slug: "Gardening"
image: "2ZBdlsXnxIbiZ8oY36lMyhJQ2Jk8T2d7YMxPq7do.jpg"
style:
background: "#2a9d8f"
background: "#d68910"
color: "#fff"
---
2 changes: 1 addition & 1 deletion content/categories/Musik/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ description: "Die Musikkategorie darf nicht fehlen. Wenn ich mal was nettes hör
slug: "musik"
image: "brigittemitamp.JPG"
style:
background: "#2a9d8f"
background: "#d98880"
color: "#fff"
---
4 changes: 2 additions & 2 deletions data/external.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ KaTeX:
defer: true

Cactus:
- src: https://latest.cactus.chat/cactus.js
- src: /cactus.js
integrity:
type: script
- src: https://latest.cactus.chat/style.css
- src: /style.css
integrity:
type: style
206 changes: 206 additions & 0 deletions public/ApiUtils.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
module ApiUtils exposing
( clientEndpoint
, httpFromMxc
, lookupHomeserverUrl
, matrixDotToUrl
, mediaEndpoint
, serverNameFromId
, thumbnailFromMxc
)

import Http
import Json.Decode as JD
import Parser exposing ((|.), (|=), Parser)
import Set
import Task exposing (Task)
import Url exposing (percentEncode)
import Url.Builder exposing (QueryParameter, crossOrigin)
import UserId exposing (UserId)



-- ENDPOINT URLS


apiEndpoint : List String -> String -> List String -> List QueryParameter -> String
apiEndpoint pathPrefix homeserverUrl path params =
crossOrigin
homeserverUrl
(List.map percentEncode <| pathPrefix ++ path)
params


clientEndpoint : String -> List String -> List QueryParameter -> String
clientEndpoint =
apiEndpoint [ "_matrix", "client", "r0" ]


mediaEndpoint : String -> List String -> List QueryParameter -> String
mediaEndpoint =
apiEndpoint [ "_matrix", "media", "r0" ]


{-| Make a matrix.to link from a matrix resource identifier.
This link can be used to access the room from other clients.
matrixDotToUrl "@asbjorn:olli.ng" == "https://matrix.to/#/%40asbjorn%3Aolli.ng"
matrixDotToUrl "#roomAlias:matrix.org" == "https://matrix.to/#/%23roomAlias%3Amatrix.org"
-}
matrixDotToUrl : String -> String
matrixDotToUrl identifier =
-- https://matrix.to/#/<identifier>
crossOrigin
"https://matrix.to"
[ "#", percentEncode identifier ]
[]


{-| Get the server name from a matrix resource identifier by splitting an identifier on ':'
serverNameFromId "@user:server.com" == Just "server.com"
serverNameFromId "#room:server.com" == Just "server.com"
serverNameFromId "foobar" == Nothing
-}
serverNameFromId : String -> Maybe String
serverNameFromId id =
if String.contains ":" id then
id
|> String.split ":"
|> (List.reverse >> List.head)

else
Nothing



-- SERVER DISCOVERY


lookupHomeserverUrl : UserId -> Task String String
lookupHomeserverUrl userid =
let
servername =
UserId.servername userid

url =
"https://" ++ servername ++ "/.well-known/matrix/client"
in
Http.task
{ method = "GET"
, url = url
, headers = []
, body = Http.emptyBody
, timeout = Nothing
, resolver =
Http.stringResolver <|
\resp ->
case resp of
Http.GoodStatus_ _ body ->
let
dropTrailingSlash : String -> String
dropTrailingSlash str =
if String.endsWith "/" str then
String.dropRight 1 str

else
str

decoder : JD.Decoder String
decoder =
JD.field "m.homeserver" (JD.field "base_url" JD.string)
|> JD.map dropTrailingSlash

decoded : Result JD.Error String
decoded =
JD.decodeString decoder body
in
case decoded of
Ok result ->
Ok result

Err err ->
Err <| JD.errorToString err

_ ->
Err <| "Failed getting " ++ url
}



-- MEDIA


{-| Parse a server name from an mxc:// url
Server name grammar found here:
<https://matrix.org/docs/spec/appendices#identifier-grammar>
-}
mxcServerName : String -> Maybe String
mxcServerName mxcUrl =
let
validChar : Char -> Bool
validChar c =
Char.isAlphaNum c || List.member c [ '.', '-', ':' ]

parser : Parser String
parser =
-- this parser sloppily allows ports in the middle of the domain
-- like "abcd:8448:wow". it's not ideal but ¯\_(ツ)_/¯
Parser.succeed identity
|. Parser.token "mxc://"
|= Parser.variable
{ start = validChar
, inner = validChar
, reserved = Set.empty
}
in
Parser.run parser mxcUrl
|> Result.toMaybe


mxcMediaId : String -> Maybe String
mxcMediaId mxcUrl =
mxcUrl
|> String.split "/"
|> (List.reverse >> List.head)


thumbnailFromMxc : String -> String -> Maybe String
thumbnailFromMxc homeserverUrl mxcUrl =
let
serverName =
mxcServerName mxcUrl

mediaId =
mxcMediaId mxcUrl
in
Maybe.map2
(\sn mid ->
mediaEndpoint homeserverUrl
[ "thumbnail", sn, mid ]
[ Url.Builder.int "width" 64
, Url.Builder.int "height" 64
, Url.Builder.string "method" "crop"
]
)
serverName
mediaId


httpFromMxc : String -> String -> Maybe String
httpFromMxc homeserverUrl mxcUrl =
let
serverName =
mxcServerName mxcUrl

mediaId =
mxcMediaId mxcUrl
in
Maybe.map2
(\sn mid -> mediaEndpoint homeserverUrl [ "download", sn, mid ] [])
serverName
mediaId
Loading

0 comments on commit 7cf202f

Please sign in to comment.