Skip to content

Commit

Permalink
Show meta tag for Open Graph Protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
windymelt committed Sep 9, 2023
1 parent 8560235 commit a87c4fc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
29 changes: 29 additions & 0 deletions modules/core/shared/src/main/scala/scaladex/core/model/OGP.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package scaladex.core.model

/**
* Open Graph Protocol, see https://ogp.me/
*
* @param title
* @param url
* @param description
* @param image
* @param imageAlt
*/
case class OGP(
title: String,
url: Url,
description: String,
image: Option[Url] = None,
imageAlt: Option[String] = None
) {
val `type`: String = "article"
val siteName: String = "Scaladex"
def toHeadMeta: Seq[HeadMeta] = Seq(
HeadMeta(name = "og:title", content = title),
HeadMeta(name = "og:url", content = url),
HeadMeta(name = "og:description", content = description),
HeadMeta(name = "og:site_name", content = siteName)
) ++ image.map(c => HeadMeta(name = "og:image", content = c.target)) ++ imageAlt.map(c =>
HeadMeta(name = "og:image:alt", c)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ case class Project(
githubInfo.flatMap(_.logo)
)

/**
* This is used in embedding to another website to render the card of a scaladex project link.
*/
def ogp: OGP = OGP(
title = s"Scaladex - ${organization.toString()} / ${repository.toString()}",
url = s"https://index.scala-lang.org/${organization.toString()}/${repository.toString()}",
description = githubInfo.flatMap[B](_.description).getOrElse(""),
image = githubInfo.flatMap(_.logo).orElse(Some("https://index.scala-lang.org/assets/img/scaladex-brand.svg")),
)

def scaladoc(artifact: Artifact): Option[DocumentationLink] =
settings.customScalaDoc
.map(DocumentationPattern("Scaladoc", _).eval(artifact))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
header: ProjectHeader,
artifact: Artifact
)
@main(env, title = project.repository.value, user, extraMeta = project.twitterCard.toHeadMeta) {
@main(env, title = project.repository.value, user, extraMeta = project.twitterCard.toHeadMeta ++ project.ogp.toHeadMeta) {
<main id="container-project">
@headproject(env, user, project, header, "Badges")
<div class="container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
directDependencies: Map[Project.Reference, (ArtifactDependency.Scope, Seq[SemanticVersion])],
reverseDependency: Map[Project.Reference, (ArtifactDependency.Scope, SemanticVersion)],
)
@main(env, title = project.repository.value, user, extraMeta = project.twitterCard.toHeadMeta) {
@main(env, title = project.repository.value, user, extraMeta = project.twitterCard.toHeadMeta ++ project.ogp.toHeadMeta) {
<main id="container-project">
@headproject(env, user, project, header, "Project")
<div class="container">
Expand Down

0 comments on commit a87c4fc

Please sign in to comment.