Skip to content

Commit

Permalink
Merge pull request #501 from zazuko/disable-schema-url
Browse files Browse the repository at this point in the history
Let the user disable schema url redirects if enabled
  • Loading branch information
ludovicm67 authored Sep 16, 2024
2 parents ea53ac9 + 972e454 commit da26557
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .changeset/tasty-ladybugs-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@zazuko/trifid-entity-renderer": patch
---

If `enableSchemaUrlRedirect` configuration option is set to `true`, the plugin is performing a redirect if the URI contains a `schema:URL` predicate pointing to a resource of type `xsd:anyURI` (already in place).

The user can now disable this behavior by either:

- setting the `disableSchemaUrlRedirect` query parameter to `true`
- setting the `x-disable-schema-url-redirect` header to `true`
3 changes: 3 additions & 0 deletions packages/entity-renderer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ The default redirect query supports `http://www.w3.org/2011/http#` and `http://w
- `replace`: the string to replace with (optional, the default value will be the current hostname)
- `enableSchemaUrlRedirect` (experimental): If set to `true`, the plugin will perform a redirect if the URI contains a `schema:URL` predicate pointing to a resource of type `xsd:anyURI`.
The default value is `false`.
If enabled, the user can still disable this behavior by either:
- setting the `disableSchemaUrlRedirect` query parameter to `true`
- setting the `x-disable-schema-url-redirect` header to `true`

## Run an example instance

Expand Down
6 changes: 5 additions & 1 deletion packages/entity-renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,16 @@ const factory = async (trifid) => {
const dataset = await rdf.dataset().import(quadStream)

if (mergedConfig.enableSchemaUrlRedirect && acceptHeader === 'text/html') {
const disabledSchemaUrlRedirect =
request.headers['x-disable-schema-url-redirect'] === 'true' ||
request.query.disableSchemaUrlRedirect === 'true'

// Get all triples that have a schema:URL property with value of type xsd:anyURI
const urls = []
dataset.match(iriUrlString, rdf.ns.schema.URL)
.filter(({ object }) => object.datatype.value === 'xsd:anyURI')
.map(({ object }) => urls.push(object.value))
if (urls.length > 0) {
if (!disabledSchemaUrlRedirect && urls.length > 0) {
const redirectUrl = urls[0]
logger.debug(`Redirecting to ${redirectUrl}`)
reply.redirect(redirectUrl)
Expand Down

0 comments on commit da26557

Please sign in to comment.