Skip to content

Commit

Permalink
Add generic home page section generation
Browse files Browse the repository at this point in the history
This change enables theme user to specify arbitrary order of sections,
and add multiple sections of the same type (more generic approach than
in gurusabarish#105, which is applicable only to experience blocks).

- All sections are specified in config as a list, with order of items
  directly reflecting order on the main page (including navbar).
- Type of a section is specified with a new `type` field.
- If there are multiple sections of the same type, in order to
  distinguish them for navbar navigation, you need to specify unique
  `id` field.
- Navbar and main page generation is more generic, allowing to add
  custom section types – the only requirement is a custom partial named
  after the section type. Styling can be provided in a custom CSS
  (enabled with `customCSS` site param).

Signed-off-by: Marek Pikuła <[email protected]>
  • Loading branch information
MarekPikula authored and thde committed Oct 23, 2024
1 parent 5878751 commit e63f70c
Show file tree
Hide file tree
Showing 14 changed files with 509 additions and 515 deletions.
527 changes: 285 additions & 242 deletions exampleSite/config.yaml

Large diffs are not rendered by default.

27 changes: 19 additions & 8 deletions layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,22 @@
{{ end }}

{{ define "main" }}
{{- partial "sections/hero/index.html" . -}}
{{- partial "sections/about.html" . -}}
{{- partial "sections/experience.html" . -}}
{{- partial "sections/education.html" . -}}
{{- partial "sections/projects.html" . -}}
{{- partial "sections/achievements.html" . -}}
{{- partial "sections/contact.html" . -}}
{{ end }}
{{ range $index, $element := (where .Site.Params.sections "enable" true) }}
{{ if not .type }}
{{ errorf "Type property needs to be set for section with index %d." $index }}
{{ else }}
{{ with $element }}
{{ $partialPathIndex := printf "sections/%s/index.html" .type }}
{{ $partialPathStandalone := printf "sections/%s.html" .type }}

{{ if templates.Exists (printf "partials/%s" $partialPathIndex) }}
{{- partial $partialPathIndex . -}}
{{ else if templates.Exists (printf "partials/%s" $partialPathStandalone) }}
{{- partial $partialPathStandalone . -}}
{{ else }}
{{ errorf "Cannot find partial for section type: %s" .type }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
32 changes: 15 additions & 17 deletions layouts/partials/sections/about.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
{{ if .Site.Params.about.enable | default false }}
<section id="about" class="py-0 py-sm-5">
<section id="{{ .id | default .type }}" class="about py-0 py-sm-5">
<div class="container bg-transparent">
<h3 class="text-center bg-transparent">{{ .Site.Params.about.title }}</h3>
<h3 class="text-center bg-transparent">{{ .title | default (strings.FirstUpper .type) }}</h3>
<div class="bg-transparent row justify-content-center px-3 py-5">
{{ if .Site.Params.about.image }}
<div class="col-sm-12 col-md-8 col-lg-4 mb-5 mb-sm-0 mb-md-5 mb-lg-0 d-none d-sm-none d-md-block">
<div class="image d-flex px-5">
<img src="{{ .Site.Params.about.image }}" class="img-thumbnail mx-auto rounded-circle" alt="">
{{ if .image }}
<div class="col-sm-12 col-md-8 col-lg-4 mb-5 mb-sm-0 mb-md-5 mb-lg-0 d-none d-sm-none d-md-block">
<div class="image d-flex px-5">
<img src="{{ .image }}" class="img-thumbnail mx-auto rounded-circle" alt="">
</div>
</div>
</div>
{{ end }}
<div class="col-sm-12 col-md-12 col-lg-8 content">
{{ .Site.Params.about.content | markdownify }}
{{ .content | markdownify }}

{{ if .Site.Params.about.skills.enable }}
{{ .Site.Params.about.skills.title }}
<ul>
{{ range .Site.Params.about.skills.items }}
<li>{{ . | markdownify }}</li>
{{ end }}
</ul>
{{ if .skills.enable }}
{{ .skills.title }}
<ul>
{{ range .skills.items }}
<li>{{ . | markdownify }}</li>
{{ end }}
</ul>
{{ end }}
</div>
</div>
</div>
</section>
{{ end }}
8 changes: 3 additions & 5 deletions layouts/partials/sections/achievements.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{{ if .Site.Params.achievements.enable | default false }}
<section id="achievements" class="py-5">
<section id="{{ .id | default .type }}" class="achievements py-5">
<div class="container">
<h3 class="text-center">{{ .Site.Params.achievements.title | default "Achievements" }}</h3>
<h3 class="text-center">{{ .title | default (strings.FirstUpper .type) }}</h3>
<div class="px-0 px-md-5 px-lg-5">
<div class="row justify-content-center px-3 px-md-5 px-lg-5">
{{ range .Site.Params.achievements.items }}
{{ range .items }}
{{ if .url }}
<div class="col-lg-4 col-md-6 my-3">
<a class="card my-3 h-100 p-3" href="{{ .url }}" title="{{ .title }}" target="_blank">
Expand Down Expand Up @@ -43,4 +42,3 @@ <h5 class="card-title bg-transparent">{{ .title }}</h5>
</div>
</div>
</section>
{{ end }}
34 changes: 16 additions & 18 deletions layouts/partials/sections/contact.html
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
{{ if .Site.Params.contact.enable | default false }}
<section id="contact" class="py-5">
<section id="{{ .id | default .type }}" class="contact py-5">
<div class="container">
<h3 class="text-center">{{ .Site.Params.contact.title | default "Get in Touch" }}</h3>
<h3 class="text-center">{{ .title | default (strings.FirstUpper .type) }}</h3>
<div class="px-0 px-md-5 px-lg-5">
<div class="row justify-content-center px-md-5">
<div class="col-md-8 py-3">
<div class="text-center">
{{ .Site.Params.contact.content | emojify | markdownify }}
{{ .content | emojify | markdownify }}
</div>
{{ if .Site.Params.contact.formspree.enable | default false }}
{{ if .formspree.enable | default false }}
<div class="row justify-content-center">
<form id="contact-form" action="https://formspree.io/f/{{ .Site.Params.contact.formspree.formId }}" onsubmit="handleFormspreeSubmit(event)" method="POST" class="col-md-7">
<form id="contact-form" action="https://formspree.io/f/{{ .formspree.formId }}" onsubmit="handleFormspreeSubmit(event)" method="POST" class="col-md-7">
<div class="form-group pt-3">
<input type="email" class="form-control" name="email" required="true" placeholder='{{ .Site.Params.contact.formspree.emailCaption | emojify | default "Enter your email" }}'>
<input type="email" class="form-control" name="email" required="true" placeholder='{{ .formspree.emailCaption | emojify | default "Enter your email" }}'>
</div>
<div class="form-group pt-3">
<textarea class="form-control" name="message" required="true" placeholder='{{ .Site.Params.contact.formspree.messageCaption | emojify | default "Enter your message" }}' rows="{{ .Site.Params.contact.formspree.messageRows | default 3 }}"></textarea>
<textarea class="form-control" name="message" required="true" placeholder='{{ .formspree.messageCaption | emojify | default "Enter your message" }}' rows="{{ .formspree.messageRows | default 3 }}"></textarea>
</div>
<div class="form-group text-center pt-3">
<button type="submit" class="btn">{{ .Site.Params.contact.btnName | default "Get in Touch" }}</button>
<button type="submit" class="btn">{{ .btnName | default "Get in Touch" }}</button>
</div>
</form>
</div>
{{ else if or (.Site.Params.contact.email) (.Site.Params.contact.btnLink) }}
{{ else if or .email .btnLink }}
<div class="text-center pt-3">
<a
href='{{ if .Site.Params.contact.btnLink }}
{{ .Site.Params.contact.btnLink | default "#" }}
{{ else }}
mailto:{{ .Site.Params.contact.email }}
{{ end }}'
<a
href='{{ if .btnLink }}
{{ .btnLink | default "#" }}
{{ else }}
mailto:{{ .email }}
{{ end }}'
target="_blank"
class="btn"
>
{{ .Site.Params.contact.btnName | default "Get in Touch" }}
{{ .btnName | default "Get in Touch" }}
</a>
</div>
{{ end }}
Expand All @@ -43,7 +42,6 @@ <h3 class="text-center">{{ .Site.Params.contact.title | default "Get in Touch" }
</div>
<div id="contact-form-status"></div>
</section>
{{ end }}

<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<symbol id="check-circle-fill" viewBox="0 0 16 16">
Expand Down
14 changes: 6 additions & 8 deletions layouts/partials/sections/education.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{{ if .Site.Params.education.enable | default false }}
<section id="education" class="py-5">
<section id="{{ .id | default .type }}" class="education py-5">
<div class="container">
<h3 class="text-center">{{ .Site.Params.education.title | default "Education" }}</h3>
<h3 class="text-center">{{ .title | default (strings.FirstUpper .type) }}</h3>
<div class="row justify-content-center py-5">
{{ $indexMenu := .Site.Params.education.index }}
{{ range $index, $element := .Site.Params.education.items }}
{{ $indexMenu := .index }}
{{ range $index, $element := .items }}
<div class="col-12 p-0">
<div class="row row align-items-center justify-content-center m-1 mb-4">
{{ if $indexMenu }}
Expand All @@ -24,7 +23,7 @@ <h3 class="text-center">{{ .Site.Params.education.title | default "Education" }}
<small>{{ .date }}</small>
</div>
<h5 class="card-title">{{ .title }}</h5>

{{ if .school.url }}
<a href="{{ .school.url }}" target="_blank">
<h6>
Expand All @@ -40,7 +39,7 @@ <h6>
GPA:
<i>
<small>{{ .GPA }}</small>
</i>
</i>
</div>
{{ end }}
<div class="py-1 education-content">
Expand All @@ -63,4 +62,3 @@ <h6>
</div>
</div>
</section>
{{ end }}
62 changes: 30 additions & 32 deletions layouts/partials/sections/experience.html
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
{{ if .Site.Params.experience.enable | default false }}
<section id="experience" class="py-5">
<section id="{{ .id | default .type }}" class="experience py-5">
<div class="container">
<h3 class="text-center">{{ .Site.Params.experience.title | default "Experience" }}</h3>
<h3 class="text-center">{{ .title | default (strings.FirstUpper .type) }}</h3>
<div class="row justify-content-center">
<div class="col-sm-12 col-md-8 col-lg-8 py-5">
<div class="experience-container px-3 pt-2">
<ul class="nav nav-pills mb-3 bg-transparent primary-font" id="pills-tab" role="tablist">
{{ range $index, $element := .Site.Params.experience.items }}
{{ range $index, $element := .items }}
{{ if (eq $index 0) }}
<li class="nav-item px-1 bg-transparent" role="presentation">
<div
class="nav-link active bg-transparent"
aria-selected="true"
role="tab"
<div
class="nav-link active bg-transparent"
aria-selected="true"
role="tab"
data-bs-toggle="pill"
id='{{ replace .company " " "-" }}-{{ replace .date " " "-" }}-tab'
data-bs-target='#pills-{{ replace .company " " "-" }}-{{ replace .date " " "-" }}'
aria-controls='{{ replace .company " " "-" }}-{{ replace .date " " "-" }}'
aria-controls='{{ replace .company " " "-" }}-{{ replace .date " " "-" }}'
>
{{ .company }}
</div>
</li>
{{ else }}
<li class="nav-item px-1 bg-transparent" role="presentation">
<div
class="nav-link bg-transparent"
aria-selected="true"
role="tab"
<div
class="nav-link bg-transparent"
aria-selected="true"
role="tab"
data-bs-toggle="pill"
id='{{ replace .company " " "-" }}-{{ replace .date " " "-" }}-tab'
data-bs-target='#pills-{{ replace .company " " "-" }}-{{ replace .date " " "-" }}'
data-bs-target='#pills-{{ replace .company " " "-" }}-{{ replace .date " " "-" }}'
aria-controls='{{ replace .company " " "-" }}-{{ replace .date " " "-" }}'
>
{{ .company }}
Expand All @@ -39,10 +38,10 @@ <h3 class="text-center">{{ .Site.Params.experience.title | default "Experience"
{{ end }}
</ul>
<div class="tab-content pb-5 pt-2 bg-transparent primary-font" id="pills-tabContent">
{{ range $index, $element := .Site.Params.experience.items }}
{{ range $index, $element := .items }}
{{ if (eq $index 0) }}
<div
class="tab-pane fade show active bg-transparent"
<div
class="tab-pane fade show active bg-transparent"
role="tabpanel"
id='pills-{{ replace .company " " "-" }}-{{ replace .date " " "-" }}'
aria-labelledby='pills-{{ replace .company " " "-" }}-{{ replace .date " " "-" }}-tab'
Expand All @@ -57,10 +56,10 @@ <h3 class="text-center">{{ .Site.Params.experience.title | default "Experience"
<small>{{ .date }}</small>
{{ if .info.enable | default true }}
<span class="p-2">
<span
style="cursor: pointer;"
data-bs-toggle="tooltip"
data-bs-placement="top"
<span
style="cursor: pointer;"
data-bs-toggle="tooltip"
data-bs-placement="top"
data-bs-original-title={{ .info.content | default (print "Working as a " .job " at " .company ) }}
>
<i class="fas fa-info-circle fa-xs"></i>
Expand All @@ -72,7 +71,7 @@ <h3 class="text-center">{{ .Site.Params.experience.title | default "Experience"
{{ if .featuredLink.enable | default false }}
<div class="py-2 featuredLink">
<a class="p-2 px-4 btn btn-outline-primary btn-sm" href={{ .featuredLink.url | default "#" }} target="_blank">
{{ .featuredLink.name | default "Featured Link" }}
{{ .featuredLink.name | default "Featured Link" }}
</a>
</div>
{{ end }}
Expand All @@ -81,8 +80,8 @@ <h3 class="text-center">{{ .Site.Params.experience.title | default "Experience"
{{ .content | markdownify}}
</div>
{{ else }}
<div
class="tab-pane fade bg-transparent"
<div
class="tab-pane fade bg-transparent"
role="tabpanel"
id='pills-{{ replace .company " " "-" }}-{{ replace .date " " "-" }}'
aria-labelledby='pills-{{ replace .company " " "-" }}-{{ replace .date " " "-" }}-tab'
Expand All @@ -98,22 +97,22 @@ <h3 class="text-center">{{ .Site.Params.experience.title | default "Experience"
<small>{{ .date }}</small>
{{ if .info.enable | default true }}
<span class="p-2">
<span
style="cursor: pointer;"
data-bs-toggle="tooltip"
data-bs-placement="top"
<span
style="cursor: pointer;"
data-bs-toggle="tooltip"
data-bs-placement="top"
data-bs-original-title={{ .info.content | default (print "Worked as a " .job " at " .company ) }}
>
>
<i class="fas fa-info-circle fa-xs"></i>
</span>
</span>
{{ end }}
</div>

{{ if .featuredLink.enable | default false }}
<div class="py-2 featuredLink">
<a class="p-2 px-4 btn btn-outline-primary btn-sm" href={{ .featuredLink.url | default "#" }} target="_blank">
{{ .featuredLink.name | default "Featured Link" }}
{{ .featuredLink.name | default "Featured Link" }}
</a>
</div>
{{ end }}
Expand All @@ -131,4 +130,3 @@ <h3 class="text-center">{{ .Site.Params.experience.title | default "Experience"
</div>
</div>
</section>
{{ end }}
Loading

0 comments on commit e63f70c

Please sign in to comment.