Skip to content

Commit

Permalink
Case class representing meta tag with "property" attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
windymelt committed Sep 9, 2023
1 parent 28a4ba6 commit 1b13332
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package scaladex.core.model

/**
* A meta tag in head that uses property attribute.
*
* @param property The property attribute
* @param content The content attribute
*/
case class HeadMetaProperty(property: String, content: String)
15 changes: 8 additions & 7 deletions modules/core/shared/src/main/scala/scaladex/core/model/OGP.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ case class OGP(
) {
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.target),
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)
def toHeadMetaProperty: Seq[HeadMetaProperty] = Seq(
HeadMetaProperty(property = "og:title", content = title),
HeadMetaProperty(property = "og:url", content = url.target),
HeadMetaProperty(property = "og:type", content = `type`),
HeadMetaProperty(property = "og:description", content = description),
HeadMetaProperty(property = "og:site_name", content = siteName)
) ++ image.map(c => HeadMetaProperty(property = "og:image", content = c.target)) ++ imageAlt.map(c =>
HeadMetaProperty(property = "og:image:alt", c)
)
}
5 changes: 5 additions & 0 deletions modules/template/src/main/twirl/scaladex/view/main.scala.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import scaladex.core.model.search.SearchParams
@import scaladex.core.model.UserState
@import scaladex.core.model.HeadMeta
@import scaladex.core.model.HeadMetaProperty
@import scaladex.core.model.Env

@(
Expand All @@ -10,6 +11,7 @@
showSearch: Boolean = true,
params: SearchParams = SearchParams(), you: Boolean = false,
extraMeta: Seq[HeadMeta] = Seq.empty,
extraMetaProperty: Seq[HeadMetaProperty] = Seq.empty,
totalProjects: Option[Long] = None, totalArtifacts: Option[Long] = None
)(content: Html)
<!DOCTYPE HTML>
Expand Down Expand Up @@ -47,6 +49,9 @@
@for(meta <- extraMeta) {
<meta name="@meta.name" content="@meta.content">
}
@for(meta <- extraMetaProperty) {
<meta property="@meta.property" content="@meta.content">
}
</head>

<body>
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 ++ project.ogp.toHeadMeta) {
@main(env, title = project.repository.value, user, extraMeta = project.twitterCard.toHeadMeta, extraMetaProperty = project.ogp.toHeadMetaProperty) {
<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 ++ project.ogp.toHeadMeta) {
@main(env, title = project.repository.value, user, extraMeta = project.twitterCard.toHeadMeta, extraMetaProperty = project.ogp.toHeadMetaProperty) {
<main id="container-project">
@headproject(env, user, project, header, "Project")
<div class="container">
Expand Down

0 comments on commit 1b13332

Please sign in to comment.