Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Commit

Permalink
add schemas (#153)
Browse files Browse the repository at this point in the history
* add schemas

* style fixes
  • Loading branch information
NikitaNaumenko authored and mokevnin committed Jan 24, 2020
1 parent 6bb4909 commit cf071a0
Show file tree
Hide file tree
Showing 16 changed files with 154 additions and 53 deletions.
48 changes: 38 additions & 10 deletions services/app/assets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ defmodule HexletBasicsWeb.Language.Module.LessonController do
use HexletBasicsWeb, :controller
alias HexletBasics.Repo
alias HexletBasicsWeb.Serializers
alias HexletBasicsWeb.Schemas.Language.ModuleSchema
alias HexletBasicsWeb.Schemas.Language.Module.LessonSchema
alias HexletBasics.User
alias HexletBasics.Language
alias HexletBasics.Language.Module.Lesson
Expand Down Expand Up @@ -41,15 +43,16 @@ defmodule HexletBasicsWeb.Language.Module.LessonController do
where: l.language_id == ^language.id and l.upload_id == ^language.upload_id and l.module_id == ^module.id,
order_by: [asc: l.order]
lessons = Repo.all(query)

schema = ModuleSchema.build(conn, module, module_description, language)
render(
conn,
language: language,
module: module,
lessons: lessons,
user_finished_lessons_by_lesson: user_finished_lessons_by_lesson,
descriptions_by_lesson: descriptions_by_lesson,
module_description: module_description
module_description: module_description,
schema: schema
)
end

Expand Down Expand Up @@ -138,6 +141,7 @@ defmodule HexletBasicsWeb.Language.Module.LessonController do
%{rel: 'image_src', href: Routes.static_url(conn, "/images/#{language.slug}.png")}
]

schema = LessonSchema.build(conn, lesson, lesson_description, lesson_theory_html)
render(conn,
language: language,
module: module,
Expand All @@ -151,6 +155,7 @@ defmodule HexletBasicsWeb.Language.Module.LessonController do
lessons_count: lessons_count,
meta_attrs: meta_attrs,
link_attrs: link_attrs,
schema: schema,
layout: {HexletBasicsWeb.LayoutView, "lesson.html"}
)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule HexletBasicsWeb.LanguageController do
use HexletBasicsWeb, :controller
alias HexletBasics.Repo
alias HexletBasicsWeb.Schemas.Language.ModuleSchema
alias HexletBasics.{Language, Language.Module, Language.Module.Lesson}
import Ecto.Query

Expand Down Expand Up @@ -78,6 +79,7 @@ defmodule HexletBasicsWeb.LanguageController do

next_lesson = next_lesson |> Repo.preload(:module)

schema = Enum.map(modules, fn module -> ModuleSchema.build(conn, module, descriptions_by_module[module.id], language) end)
title_text = Gettext.gettext(HexletBasicsWeb.Gettext, "OG title #{language.slug}")
header = Gettext.gettext(HexletBasicsWeb.Gettext, "Header #{language.slug}")

Expand Down Expand Up @@ -107,7 +109,8 @@ defmodule HexletBasicsWeb.LanguageController do
meta_attrs: meta_attrs,
link_attrs: link_attrs,
title: title_text,
header: header
header: header,
schema: schema
)
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule HexletBasicsWeb.PageController do
use HexletBasicsWeb, :controller
alias HexletBasicsWeb.Plugs.DetectDomainForRoot
alias HexletBasicsWeb.Schemas.CompanySchema

plug DetectDomainForRoot when action in [:index]

Expand Down Expand Up @@ -43,7 +44,8 @@ defmodule HexletBasicsWeb.PageController do
started_languages_by_slug: started_languages_by_slug,
meta_attrs: meta_attrs,
link_attrs: link_attrs,
title: title_text
title: title_text,
schema: CompanySchema.build(conn)
)
end

Expand Down
33 changes: 33 additions & 0 deletions services/app/lib/hexlet_basics_web/schemas/company_schema.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
defmodule HexletBasicsWeb.Schemas.CompanySchema do
alias HexletBasicsWeb.Router.Helpers, as: Routes

def build(conn) do
%{
"@context": "https://schema.org",
"@type": "Organization",
url: "http://hexlet.io",
name: "Hexlet",
legalName: "Hexlet Ltd.",
vatID: "VAT ID: FI26641607",
telephone: "+44 20 3514 2938",
sameAs: [
"https://www.facebook.com/Hexlet",
"https://www.youtube.com/user/HexletUniversity",
"https://twitter.com/HexletHQ",
"https://soundcloud.com/hexlet"
],
address: %{
"@type": "PostalAddress",
name: "Puolikkotie 8, 02230 Espoo, Finland"
},
logo: %{
"@type": "ImageObject",
url: Routes.static_url(conn, "/images/hexlet_logo.png")
},
email: %{
"@type": "Text",
"@id": "mailto:support@hexlet.io"
}
}
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
defmodule HexletBasicsWeb.Schemas.Language.Module.LessonSchema do
alias HexletBasicsWeb.Schemas.CompanySchema
alias HexletBasicsWeb.Router.Helpers, as: Routes

def build(conn, lesson, lesson_description, lesson_theory_html) do
%{
"@context": "https://schema.org",
"@type": "TechArticle",
author: Gettext.gettext(HexletBasicsWeb.Gettext, "Code Basics Author"),
headline: lesson_description.name,
datePublished: lesson.inserted_at,
dateModified: lesson.updated_at,
image: Routes.static_url(conn, "/images/smm_cover.jpg"),
accessMode: "textOnVisual",
publisher: CompanySchema.build(conn),
hasPart: %{
"@context": "https://schema.org",
"@type": "WebPageElement",
isAccessibleForFree: "https://schema.org/True",
value: HtmlSanitizeEx.strip_tags(lesson_theory_html)
}
}
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
defmodule HexletBasicsWeb.Schemas.Language.ModuleSchema do
alias HexletBasicsWeb.Schemas.CompanySchema
alias HexletBasicsWeb.Router.Helpers, as: Routes

def build(conn, module, module_description, language) do
%{
"@context": "https://schema.org",
"@type": "Course",
name: module_description.name,
description: module_description.description,
accessMode: "textOnVisual",
isAccessibleForFree: "https://schema.org/True",
url: Routes.language_module_lesson_path(conn, :index, language.slug, module.slug),
provider: CompanySchema.build(conn)
}
end
end
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
div(itemscope itemtype="http://schema.org/Course")
span(itemprop="provider" itemscope itemtype="http://schema.org/Organization")
= render HexletBasicsWeb.LayoutView, "shared/schemas/company.html", assigns

div
.row.mt-5.d-flex.flex-row
.col-12
- module_description = @module_description
h2 itemprop="name"
h2
= module_description.name
.show id="module_#{@module.id}"
.row.d-flex.flex-row
Expand All @@ -26,4 +23,4 @@ div(itemscope itemtype="http://schema.org/Course")
= lesson_description.name

.col-12.col-md-6.mt-3
p.lead itemprop="description"= module_description.description
p.lead= module_description.description
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,9 @@
a.nav-link href="#discuss-tab" data-toggle="tab" role="tab"= gettext "discuss"

.card-body.overflow-auto
.tab-content(itemscope itemtype="http://schema.org/TechArticle")
meta content="#{gettext("Code Basics Author")}" itemprop="author"
meta content=@module_description.description itemprop="description"
meta content=@lesson_inserted_at itemprop="datePublished"
meta content="true" itemprop="isAccessibleForFree"
meta content=@lesson_updated_at itemprop="dateModified"
meta content="/images/smm_cover.jpg" itemprop="image"

span(itemprop="publisher" itemscope itemtype="http://schema.org/Organization")
= render HexletBasicsWeb.LayoutView, "shared/schemas/company.html", assigns

.tab-content
.tab-pane.fade.show.active#lesson-tab(role="tabpanel")
h1(itemprop="headline")= @lesson_description.name
h1= @lesson_description.name
== @lesson_theory_html
h2= gettext "instructions"
== @lesson_instructions_html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ h1.text-center.display-3= @header
== gettext("Try Hexlet %{courses} or join to %{professions}", courses: safe_to_string(course_link), professions: safe_to_string(professions_link))

= for module <- @modules do
div(itemscope itemtype="http://schema.org/Course")
span(itemprop="provider" itemscope itemtype="http://schema.org/Organization")
= render HexletBasicsWeb.LayoutView, "shared/schemas/company.html", assigns

div
.row.mt-5.d-flex.flex-row
.col-12
- module_description = @descriptions_by_module[module.id]
h2 itemprop="name"
h2
= module_description.name
.row.d-flex.flex-row
.col-12.col-md-6.mt-4
Expand All @@ -41,4 +38,5 @@ h1.text-center.display-3= @header
i class="text-primary fas fa-check"

.col-12.col-md-6.mt-3
div itemprop="description"= module_description.description
div
= module_description.description
Loading

0 comments on commit cf071a0

Please sign in to comment.