Skip to content

Commit

Permalink
Merge pull request #16 from NBISweden/search-function
Browse files Browse the repository at this point in the history
Search function
  • Loading branch information
darthvader2 authored Jun 12, 2024
2 parents 8b7cf77 + de09893 commit 8a7c9a2
Show file tree
Hide file tree
Showing 15 changed files with 373 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
web/content/datasets/*
charts/
dev_utils/
dev_utils/*
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
web/public/*
web/content/datasets/test*
web/data/*
dev_utils/config.yaml
web/static/pagefind/*
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ RUN go build -o app .

FROM alpine:3.17
RUN apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community hugo
RUN wget https://github.com/CloudCannon/pagefind/releases/download/v1.1.0/pagefind-v1.1.0-x86_64-unknown-linux-musl.tar.gz && \
tar -xvf pagefind-v1.1.0-x86_64-unknown-linux-musl.tar.gz && \
mv pagefind /usr/bin && \
rm pagefind-v1.1.0-x86_64-unknown-linux-musl.tar.gz
COPY --from=build /lp_app/app .
COPY --from=build /lp_app/web web/
CMD ["./app"]
4 changes: 1 addition & 3 deletions download_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ func metadataDownloader(Metadataclient *MetadataBackend) {
err := downloadToFile(manager, LocalDirectory, Bucket, aws.ToString(obj.Key))
if err != nil {
log.Fatal("Error while downloading metadata files from metadata bucket", err)
} else {
log.Infoln("Completed downloading metadatafiles")

}
}
log.Infoln("Completed downloading metadata files")

}

Expand Down
48 changes: 48 additions & 0 deletions header_extractor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"encoding/xml"
"log"
"os"
)

// Struct definitions
type LandingPageSet struct {
LandingPage LandingPage `xml:"LANDING_PAGE"`
}

type LandingPage struct {
Attributes Attributes `xml:"ATTRIBUTES"`
}

type Attributes struct {
StringAttributes []StringAttribute `xml:"STRING_ATTRIBUTE"`
}

type StringAttribute struct {
Tag string `xml:"TAG"`
Value string `xml:"VALUE"`
}

// Function to extract header value from XML content
func getHeaderValueFromXMLContent(xmlContent []byte) (string, error) {
var landingPageSet LandingPageSet
err := xml.Unmarshal(xmlContent, &landingPageSet)
if err != nil {
log.Fatal("Unmarshalling XML file for header failed", err)
}

// Iterate over the string attributes to find the header value
for _, attr := range landingPageSet.LandingPage.Attributes.StringAttributes {
if attr.Tag == "header" {
return attr.Value, nil
}
}
return "sf", err

}

// Function to read the XML file and return its content
func readXMLFile(filePath string) ([]byte, error) {
return os.ReadFile(filePath)
}
25 changes: 19 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"os"
"os/exec"

log "github.com/sirupsen/logrus"
Expand All @@ -11,16 +12,28 @@ func main() {
log.Infoln("started app successfully")
mConf := getMetadataConfig()
Metadataclient := connectMetadatas3(mConf)
log.Infof("Connection to the bucket established")
log.Infof("Writing markdownfiles for respective XMLs")
metadataDownloader(Metadataclient)
markDownCreator()
cmd := exec.Command("hugo")
cmd.Dir = "./web/"
cmd.Run()
hugo_cmd := exec.Command("hugo")
hugo_cmd.Dir = "./web/"
hugo_cmd.Stdout = os.Stdout
hugo_cmd.Stderr = os.Stderr
err := hugo_cmd.Run()
if err != nil {
log.Fatal(err)
}
log.Infof("Hugo successfully built")
pagefind_cmd := exec.Command("pagefind", "--site", "web/public/", "--output-path", "web/static/pagefind/")
pagefind_cmd.Stdout = os.Stdout
pagefind_cmd.Stderr = os.Stderr
pagefind_err := pagefind_cmd.Run()
if pagefind_err != nil {
log.Fatal(pagefind_err)
}
log.Infof("Pagefind modules successfully built")
dConf := getDeploymentConfig()
DeploymenClient := connectDeployments3(dConf)
log.Infof("Connection to the bucket established")
test(DeploymenClient)
staticSiteUploader(DeploymenClient)

}
19 changes: 15 additions & 4 deletions markdown_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,30 @@ func markDownCreator() {

// Read XML file name
xmlFileName := filepath.Base(xmlFilePath)
log.Debug(xmlFilePath)
xmlContent, err := readXMLFile(xmlFilePath)
if err != nil {
log.Fatalf("Error reading the XML file %V", err)
}
headerValue, err := getHeaderValueFromXMLContent(xmlContent)
if err != nil {
log.Fatal("Error while getting header value from XML file", err)
}

log.Debugln("Header value: %V", headerValue)
// Remove file extension
fileNameWithoutExt := strings.TrimSuffix(xmlFileName, filepath.Ext(xmlFileName))

// Markdown content
markdownContent := fmt.Sprintf(`
---
markdownContent := fmt.Sprintf(`---
title: "%s"
---
{{< datafetch variable="%s" >}}
Filename of the associated XML file: %s
`, fileNameWithoutExt, xmlFileName)
`, headerValue, fileNameWithoutExt, xmlFileName)

// Create Markdown file
mdFileName := filepath.Join(markdownDir, fileNameWithoutExt+".md")
Expand All @@ -66,12 +76,13 @@ Filename of the associated XML file: %s
return nil
}

log.Infoln("Markdown file %S created successfully!\n", mdFileName)
log.Debug("Markdown file %S created successfully!\n", mdFileName)

return nil
})

if err != nil {
log.Fatal("Error walking through directory:", err)
}

}
9 changes: 7 additions & 2 deletions static_files_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/s3"
)

func test(DeploymenClient *DeploymentBackend) {
func staticSiteUploader(DeploymenClient *DeploymentBackend) {
var (
localPath = "web/public/"
bucket = DeploymenClient.Bucket
Expand Down Expand Up @@ -50,6 +50,9 @@ func test(DeploymenClient *DeploymentBackend) {
if ext == ".css" {
contentType = "text/css;"
}
if ext == ".svg" {
contentType = "image/svg+xml;"
}

if err != nil {
log.Fatalln("File bytes empty", path, err)
Expand All @@ -68,8 +71,10 @@ func test(DeploymenClient *DeploymentBackend) {
if err != nil {
log.Fatalln("Failed to upload", path, err)
}
log.Infoln("Uploaded", path, result.Location)
log.Debugln("Uploaded", path, result.Location)
}
log.Infoln("Successfully uploaded built static site to the bucket")

}

type fileWalk chan string
Expand Down
2 changes: 1 addition & 1 deletion web/content/datasets/_index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Test"
title: "Search"
date: 2024-03-20T10:31:33+01:00
layout: test
---
9 changes: 4 additions & 5 deletions web/layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
<html lang="{{ .Site.LanguageCode }}">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{{ partial "head.html" . }}
{{ partial "nav.html" . }}

<body>
{{ partial "nav.html" . }}
<!-- Page Header -->
{{ block "header" .}}

<header class="page-header" ,role="banner" >
<h1 class="project-name" >{{ .Site.Title}} </h1>
<h2 class="project-tagline">{{ .Site.Params.slogan }}</h2>
</header>
{{ end }}
<body>
<main id="content" class="main-content" role="main">
<main id="content" class="main-content" role="main">
{{ block "main" . }}

{{ end }}
Expand Down
12 changes: 9 additions & 3 deletions web/layouts/datasets/list.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
{{ define "main" }}
<h2> Bigpicture Datasets</h2>
<ul>

<div id="search">
<script>
window.addEventListener('DOMContentLoaded', (event) => {
new PagefindUI({ element: "#search", showSubResults: true });
});
</script>
<ul data-pagefind-ignore >
{{ range .Pages }}
<a href="{{ .RelPermalink }}"><p>HUS mock dataset</p></a>
<a href="{{ .RelPermalink }}"><p>{{ .Params.title }}</p></a>

{{ end }}
</ul>
{{ .Params.datasets.name }}
{{ .Content }}
{{ end }}
3 changes: 3 additions & 0 deletions web/layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<link rel="canonical" href="{{ .RelPermalink }}">

<link rel="stylesheet" href="{{ "css/style.css" | relURL }}">
<link rel="stylesheet" href="{{ "pagefind/pagefind-ui.css" | relURL}}" >

<script src="{{ "pagefind/pagefind-ui.js" | relURL}}"></script>

<!-- Custom Fonts -->
<link href="https://cdn.jsdelivr.net/gh/FortAwesome/[email protected]/css/all.css" rel="stylesheet" type="text/css">
Expand Down
32 changes: 24 additions & 8 deletions web/layouts/partials/nav.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@


<div class="topnav">
<div class="topnav" id="navbar">



<!-- Left-aligned links (default) -->

<a href="{{.Site.BaseURL}}">Home</a>
<script>
var navbar = document.getElementById('navbar');
var navbarHeight = navbar.offsetHeight;
window.addEventListener('scroll', function() {
if (window.scrollY > 0) {
navbar.classList.add('shrink');
} else {
navbar.classList.remove('shrink');
navbar.style.position = 'initial';
}
if (window.scrollY >= navbarHeight) {
navbar.style.position = 'fixed';
navbar.style.top = '0';
}
});
</script>

<div class="logo-nav-container">
<img id = "nav-logo" src="{{.Site.BaseURL}}/img/bigpicture_logo.svg">
</div>
<div class="nav-links">
<a href="{{.Site.BaseURL}}/">Home</a>
<a href="{{.Site.BaseURL}}/datasets.html">Datasets</a>


</div>
</div>


Expand Down
Loading

0 comments on commit 8a7c9a2

Please sign in to comment.