Skip to content

Commit

Permalink
Implemented search using pagefind
Browse files Browse the repository at this point in the history
  • Loading branch information
agaetep committed Aug 28, 2024
1 parent f9cefe2 commit afae172
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public/
pagefind
71 changes: 51 additions & 20 deletions themes/osuosl/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -121,36 +121,67 @@ textarea {
font-weight: bold;
}

.search-container {
margin: 1.4em;
.search-modal {
display: none;
}

.search-form {
.search-modal.show {
display: flex;
margin: 0;
flex-direction: column;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: 1000;
align-items: center;
justify-content: center;
}

.search {
border-radius: 12px 0 0 12px;
border: medium none;
padding: 6px;
margin: 0;
width: 100px;
.search-modal.hide {
display: none;
}

.submit-search {
border-radius: 0 12px 12px 0;
border-style: none;
padding: 5px;
margin: 0;
height: 33px;
width: 40px;
cursor: pointer;
background: black;
.search-headers {
display: flex;
justify-content: space-between;
align-items: center;
}

.fa-search {
.close-search {
height: fit-content;
border: none;
background: white;
}

.close-search i {
font-size: x-large;
}

.search-modal-container {
background: white;
width: 56rem;
height: 90vh;
overflow: scroll;
margin: 50px;
padding: 20px;
}

.open-search {
border-radius: 10px;
border-style: none;
padding: 5px;
margin: 1em;
height: 33px;
width: 40px;
cursor: pointer;
color: white;
background: none;
}

.open-search:hover {
background: black;
}

/*
Expand Down
1 change: 1 addition & 0 deletions themes/osuosl/layouts/_default/baseof.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html>
{{ partial "search.html" . }}
{{- partial "head.html" . -}}
<body>
{{- partial "header.html" . -}}
Expand Down
2 changes: 1 addition & 1 deletion themes/osuosl/layouts/_default/list.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ define "main" }}
<main class="main_content">
{{- partial "menu.html" . -}}
<h1>{{ .Title }}</h1>
<h1 data-pagefind-meta="title">{{ .Title }}</h1>
<div>
{{ .Content }}
</div>
Expand Down
2 changes: 1 addition & 1 deletion themes/osuosl/layouts/_default/single.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ define "main" }}
<main class="main_content">
{{- partial "menu.html" . -}}
<h1>{{ .Title }}</h1>
<h1 data-pagefind-meta="title">{{ .Title }}</h1>
<div>
{{ .Content }}
</div>
Expand Down
2 changes: 1 addition & 1 deletion themes/osuosl/layouts/_default/summary.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<article class="list__item post">
{{ partial "post_thumbnail.html" (dict "class" "list" "page" .) }}
<header class="list__header">
<h2 class="list__title post__title">
<h2 data-pagefind-meta="title" class="list__title post__title">
<a href="{{ .RelPermalink }}" rel="bookmark">
{{ .Title }}
</a>
Expand Down
1 change: 1 addition & 0 deletions themes/osuosl/layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script type="text/javascript" src="/js/carousel.js"></script>
<script type="text/javascript" src="/js/mobile-menu.js"></script>
<script type="text/javascript" src="/js/search-modal.js"></script>
</head>
5 changes: 1 addition & 4 deletions themes/osuosl/layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
</a>
</div>
<div class="search-container">
<form class="search-form">
<input class="search" type="text" placeholder="Search this site">
<button type="submit" class="submit-search"><i class="fa-solid fa-search"></i></button>
</form>
<button class="open-search" id="open-search"><i class="fa-solid fa-search"></i></button>
</div>
<div class="mobile-menu-container">
<a class="toggle-mobile-menu" id="toggle-mobile-menu"><i class="fa-solid fa-bars"></i></a>
Expand Down
1 change: 0 additions & 1 deletion themes/osuosl/layouts/partials/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
<a class="menu__link thirdmenu__link" href="{{ .URL }}">
{{ .Pre }}
<span class="menu__text thirdmenu__text">{{ .Name }}</span>
<label></label>
{{ .Post }}
</a>
</li>
Expand Down
26 changes: 26 additions & 0 deletions themes/osuosl/layouts/partials/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<link href="/pagefind/pagefind-ui.css" rel="stylesheet">
<script src="/pagefind/pagefind-ui.js"></script>

<div class="search-modal">
<div class="search-modal-container">
<div class="search-headers">
<h1>Search</h1>
<button class="close-search" id="close-search"><i class="fa fa-times" aria-hidden="true"></i></button>
</div>
<div id="search"></div>
</div>
</div>

<script>
window.addEventListener('DOMContentLoaded', (event) => {
new PagefindUI({
element: "#search",
showImages: false,
showSubResults: true,
processResult: function(result) {
result.title = result.metaTitle
return result;
}
});
});
</script>
14 changes: 14 additions & 0 deletions themes/osuosl/static/js/search-modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
document.addEventListener('DOMContentLoaded', function () {
var button = document.getElementById("open-search");
var menu = document.querySelector(".search-modal");
var close = document.getElementById("close-search")
button.addEventListener("click", function () {
menu.classList.add("show");
menu.classList.remove("hide");
});

close.addEventListener("click", function () {
menu.classList.add("hide");
menu.classList.remove("show");
});
})

0 comments on commit afae172

Please sign in to comment.