Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open Graph Protocol metadata for version pages #284

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions assets/elm_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions src/backend/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,16 @@ serveVersion memory author project maybeVersion info =
Nothing ->
S.pass

Just (Memory.Summary versions _ _) ->
Just (Memory.Summary versions maybeDetails _) ->
case verifyVersion maybeVersion versions of
Nothing ->
S.pass

Just version ->
case info of
Readme ->
ServeFile.version name version Nothing
ServeFile.version name version Nothing $
maybe Nothing (Just . fst) maybeDetails

Module asset ->
serveVersionHelp name version asset
Expand All @@ -220,7 +221,7 @@ serveVersionHelp name version asset =
_ ->
case Module.fromHyphenPath asset of
Just moduleName ->
ServeFile.version name version (Just moduleName)
ServeFile.version name version (Just moduleName) Nothing

Nothing ->
S.pass
Expand Down
39 changes: 32 additions & 7 deletions src/backend/ServeFile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import qualified Elm.Package as Pkg

misc :: B.Builder -> Snap ()
misc title =
makeHtml title mempty
makeHtml title mempty (makeOgpMetadata title Nothing)



Expand All @@ -37,15 +37,18 @@ misc title =

project :: Pkg.Name -> Snap ()
project pkg =
makeHtml (B.stringUtf8 (Pkg.toString pkg)) mempty
let
title = (B.stringUtf8 (Pkg.toString pkg))
in
makeHtml title mempty (makeOgpMetadata title Nothing)



-- VERSION


version :: Pkg.Name -> Pkg.Version -> Maybe Module.Raw -> Snap ()
version pkg@(Pkg.Name _ prjct) vsn maybeName =
version :: Pkg.Name -> Pkg.Version -> Maybe Module.Raw -> Maybe Text.Text -> Snap ()
version pkg@(Pkg.Name _ prjct) vsn maybeName maybeDescription =
let
versionString =
Pkg.versionToString vsn
Expand All @@ -56,8 +59,14 @@ version pkg@(Pkg.Name _ prjct) vsn maybeName =
title =
maybe "" (++" - ") maybeStringName
++ Text.unpack prjct ++ " " ++ versionString

ogpTitle =
maybe "" (++" - ") maybeStringName
++ Pkg.toString pkg ++ " " ++ versionString

in
makeHtml (B.stringUtf8 title) (makeCanonicalLink pkg maybeName)
(makeOgpMetadata (B.stringUtf8 ogpTitle) maybeDescription)



Expand Down Expand Up @@ -106,19 +115,35 @@ renames =
(,)


-- OGP METADATA

makeOgpMetadata :: B.Builder -> Maybe Text.Text -> B.Builder
makeOgpMetadata title maybeDescription =
let
description =
maybe "" (B.stringUtf8 . Text.unpack . \d ->
[r|<meta property="og:description" content="|] <> d <> [r|">|]
) maybeDescription
in
[r|<meta property="og:type" content="website">
<meta property="og:site_name" content="Elm Packages">
<meta property="og:title" content="|] <> title <> [r|">
<meta property="og:image" content="http://localhost:8080/assets/elm_logo.svg">|]
<> description


-- SKELETON


makeHtml :: B.Builder -> B.Builder -> Snap ()
makeHtml title canonicalLink =
makeHtml :: B.Builder -> B.Builder -> B.Builder -> Snap ()
makeHtml title canonicalLink ogpMetadata =
writeBuilder $
[r|<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<link rel="shortcut icon" size="16x16, 32x32, 48x48, 64x64, 128x128, 256x256" href="/assets/favicon.ico">
<title>|] <> title <> [r|</title>|] <> canonicalLink <> [r|
<title>|] <> title <> [r|</title>|] <> canonicalLink <> ogpMetadata <> [r|
<link rel="stylesheet" href="/assets/highlight/styles/default.css?|] <> uniqueToken <> [r|">
<link rel="stylesheet" href="/assets/style.css?|] <> uniqueToken <> [r|">
<script src="/assets/highlight/highlight.pack.js?|] <> uniqueToken <> [r|"></script>
Expand Down