-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1135 from research-software-directory/codemeta-ov…
…erview CodeMeta overview page
- Loading branch information
Showing
6 changed files
with
127 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ COPY **.go . | |
|
||
RUN go build -v -o /usr/local/bin/app | ||
|
||
COPY **.gohtml . | ||
|
||
RUN useradd user | ||
USER user | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2024 Netherlands eScience Center | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"html/template" | ||
"io" | ||
) | ||
|
||
type SoftwareBasicData struct { | ||
Slug string `json:"slug"` | ||
BrandName string `json:"brand_name"` | ||
ShortStatement string `json:"short_statement"` | ||
} | ||
|
||
var tmpl = template.Must(template.ParseFiles("overview.gohtml")) | ||
|
||
func GenerateOverview(bytes []byte, writer io.Writer) error { | ||
var software []SoftwareBasicData | ||
err := json.Unmarshal(bytes, &software) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = tmpl.Execute(writer, software) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>CodeMeta overview</title> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/[email protected]/css/pico.min.css"> | ||
</head> | ||
<body class="container"> | ||
<h1> | ||
CodeMeta overview | ||
</h1> | ||
<section> | ||
This page gives a succinct overview of all software pages that export to CodeMeta. | ||
<mark><strong>Warning</strong>: this feature is still in development, so the generated CodeMeta data might still | ||
change. | ||
</mark> | ||
</section> | ||
<section>{{range .}} | ||
<article> | ||
<header><a href="v3/{{.Slug}}/">{{.BrandName}}</a></header>{{.ShortStatement}} | ||
</article>{{end}} | ||
</section> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2024 Netherlands eScience Center | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"errors" | ||
"io" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
func GetAndReadBody(url string) (body []byte, err error) { | ||
resp, err := http.Get(url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer func(Body io.ReadCloser) { | ||
closeErr := Body.Close() | ||
if closeErr != nil { | ||
log.Printf("Unknown error when closing response body for URL %v overview with error: %v", url, closeErr) | ||
err = errors.Join(closeErr, err) | ||
} | ||
}(resp.Body) | ||
|
||
body, err = io.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return body, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters