Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
sroertgen committed Nov 7, 2023
2 parents d154ace + 1d2af17 commit 082106f
Show file tree
Hide file tree
Showing 24 changed files with 2,258 additions and 1,161 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ docker run \
skohub/skohub-vocabs-docker:latest
```

## Validation of SKOS files

During the build the provided SKOS files are validated against this [SkoHub SHACL shape](https://github.com/skohub-io/shapes/blob/main/skohub.shacl.ttl).
The SkoHub SHACL shape is an opinionated and more restrictive version of the generic SKOS shape you can find in the same repo: https://github.com/skohub-io/shapes

If the SKOS file violates the shape, the build will error and stop.
If you just hit warnings you will see them in the console output.

## Serve from other location than root (`/`)

Expand All @@ -117,6 +124,7 @@ To start configuring copy the default file `cp config.default.yaml config.yaml`.
You can configure the following settings:

- Tokenizer used for searching
- Custom Domain
- UI Configurations
- Title
- Logo
Expand All @@ -128,10 +136,18 @@ The settings are explained in the following sections.
### Tokenizer

SkoHub Vocabs uses Flexsearch v0.6.32 for its searching capabilities.
Flexsearch offers [different tokenizers](https://github.com/nextapps-de/flexsearch/tree/0.6.32#tokenizer) for indexing your vocabularies.
Flexsearch offers [different tokenizers](https://github.com/nextapps-de/flexsearch#tokenizer-prefix-search) for indexing your vocabularies.
The chosen tokenizer directly affects the required memory and size of your index file.
SkoHub Vocabs defaults to `full` tokenizer.

### Custom Domain

If you want to host your vocabularies under a custom domain (so no W3 perma-id or purl.org redirect), you have to provide that domain in the config.
Example:

The base of your concept scheme is: `http://my-awesome-domain.org/my-vocab`
Then provide `http://my-awesome-domain.org` as `custom_domain` in your `config.yaml`

### UI

The following customizations can be made:
Expand Down
3 changes: 2 additions & 1 deletion config.default.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
# see https://github.com/nextapps-de/flexsearch/tree/0.6.32#tokenizer for options
# see https://github.com/nextapps-de/flexsearch#tokenizer-prefix-search for options
tokenizer: "full" # strict, forward, reverse, full
custom_domain: ""
searchableAttributes:
- "prefLabel" # you should not delete this one
- "notation"
Expand Down
1 change: 1 addition & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
logo: config.logo,
fonts: config.fonts,
searchableAttributes: config.searchableAttributes,
customDomain: config.customDomain,
},
pathPrefix: `${process.env.BASEURL || ""}`,
plugins: [
Expand Down
53 changes: 42 additions & 11 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ const path = require("path")
const fs = require("fs-extra")
const { Index, Document } = require("flexsearch")
const omitEmpty = require("omit-empty")
const { i18n, getFilePath, parseLanguages } = require("./src/common")
const {
i18n,
getFilePath,
parseLanguages,
loadConfig,
} = require("./src/common")
const context = require("./src/context")
const queries = require("./src/queries")
const types = require("./src/types")
const { validate } = require("./src/validate.js")

require("dotenv").config()
require("graceful-fs").gracefulify(require("fs"))

const config = loadConfig("./config.yaml", "./config.default.yaml")
const languages = new Set()
const languagesByCS = {}
const inverses = {
Expand Down Expand Up @@ -84,7 +91,8 @@ const exportIndex = (index, conceptScheme, language) => {
(conceptScheme.id.endsWith("/")
? conceptScheme.id.slice(0, -1)
: conceptScheme.id) + `-cs/search/${language}/${key}`,
`json`
`json`,
config.customDomain
)
createData({
path,
Expand All @@ -104,6 +112,13 @@ exports.onPreBootstrap = async ({ createContentDigest, actions, getNode }) => {
console.info(`Found these turtle files:`)
ttlFiles.forEach((e) => console.info(e))
for (const f of ttlFiles) {
try {
console.info("Validating: ", f)
await validate("shapes/skohub.shacl.ttl", f)
} catch (e) {
console.error(e)
throw e
}
const ttlString = fs.readFileSync(f).toString()
const doc = await jsonld.fromRDF(ttlString, { format: "text/turtle" })
const compacted = await jsonld.compact(doc, context.jsonld)
Expand Down Expand Up @@ -234,20 +249,25 @@ exports.createPages = async ({ graphql, actions: { createPage } }) => {
const jsonld = omitEmpty(Object.assign({}, collection, context.jsonld))
languages.forEach((language) =>
createPage({
path: getFilePath(collection.id, `${language}.html`),
path: getFilePath(
collection.id,
`${language}.html`,
config.customDomain
),
component: path.resolve(`./src/components/Collection.jsx`),
context: {
language,
node: collection,
customDomain: config.customDomain,
},
})
)
createData({
path: getFilePath(collection.id, "json"),
path: getFilePath(collection.id, "json", config.customDomain),
data: JSON.stringify(json, null, 2),
})
createData({
path: getFilePath(collection.id, "jsonld"),
path: getFilePath(collection.id, "jsonld", config.customDomain),
data: JSON.stringify(jsonld, null, 2),
})
})
Expand Down Expand Up @@ -313,23 +333,28 @@ exports.createPages = async ({ graphql, actions: { createPage } }) => {
// create pages and data
languagesOfCS.forEach((language) =>
createPage({
path: getFilePath(concept.id, `${language}.html`),
path: getFilePath(
concept.id,
`${language}.html`,
config.customDomain
),
component: path.resolve(`./src/components/Concept.jsx`),
context: {
language,
node: concept,
collections: memberOf.hasOwnProperty(concept.id)
? memberOf[concept.id]
: [],
customDomain: config.customDomain,
},
})
)
createData({
path: getFilePath(concept.id, "json"),
path: getFilePath(concept.id, "json", config.customDomain),
data: JSON.stringify(json, null, 2),
})
createData({
path: getFilePath(concept.id, "jsonld"),
path: getFilePath(concept.id, "jsonld", config.customDomain),
data: JSON.stringify(jsonld, null, 2),
})
}
Expand Down Expand Up @@ -361,23 +386,28 @@ exports.createPages = async ({ graphql, actions: { createPage } }) => {
})
languagesOfCS.forEach((language) =>
createPage({
path: getFilePath(conceptScheme.id, `${language}.html`),
path: getFilePath(
conceptScheme.id,
`${language}.html`,
config.customDomain
),
component: path.resolve(`./src/components/ConceptScheme.jsx`),
context: {
language,
node: conceptScheme,
embed: embeddedConcepts,
customDomain: config.customDomain,
},
})
)
createData({
path: getFilePath(conceptScheme.id, "json"),
path: getFilePath(conceptScheme.id, "json", config.customDomain),
data: JSON.stringify(
omitEmpty(Object.assign({}, conceptScheme, context.jsonld), null, 2)
),
})
createData({
path: getFilePath(conceptScheme.id, "jsonld"),
path: getFilePath(conceptScheme.id, "jsonld", config.customDomain),
data: JSON.stringify(
omitEmpty(Object.assign({}, conceptScheme, context.jsonld), null, 2)
),
Expand Down Expand Up @@ -405,6 +435,7 @@ exports.createPages = async ({ graphql, actions: { createPage } }) => {
return [key, Array.from(value)]
})
),
customDomain: config.customDomain,
},
})
)
Expand Down
Loading

0 comments on commit 082106f

Please sign in to comment.