resolver: Use custom template
This commit is contained in:
parent
a292c25f84
commit
729b9cfb51
4 changed files with 102 additions and 6 deletions
|
|
@ -10,15 +10,21 @@ import (
|
|||
"github.com/FAU-CDI/wdresolve"
|
||||
"github.com/FAU-CDI/wdresolve/resolvers"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/static"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/static/custom"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/lazy"
|
||||
"github.com/rs/zerolog"
|
||||
|
||||
_ "embed"
|
||||
)
|
||||
|
||||
type Resolver struct {
|
||||
component.Base
|
||||
Dependencies struct {
|
||||
Instances *instances.Instances
|
||||
Custom *custom.Custom
|
||||
}
|
||||
|
||||
prefixes lazy.Lazy[map[string]string] // cached prefixes (from the server)
|
||||
|
|
@ -39,11 +45,30 @@ func (resolver *Resolver) Routes() component.Routes {
|
|||
}
|
||||
}
|
||||
|
||||
//go:embed "resolver.html"
|
||||
var resolverHTMLStr string
|
||||
var resolverTemplate = static.AssetsHome.MustParseShared("resolver.html", resolverHTMLStr)
|
||||
|
||||
type resolverContext struct {
|
||||
custom.BaseContext
|
||||
wdresolve.IndexContext
|
||||
}
|
||||
|
||||
func (resolver *Resolver) HandleRoute(ctx context.Context, route string) (http.Handler, error) {
|
||||
resolverTemplate := resolver.Dependencies.Custom.Template(resolverTemplate)
|
||||
|
||||
logger := zerolog.Ctx(ctx)
|
||||
|
||||
var err error
|
||||
return resolver.handler.Get(func() (p wdresolve.ResolveHandler) {
|
||||
p.HandleIndex = func(context wdresolve.IndexContext, w http.ResponseWriter, r *http.Request) {
|
||||
ctx := resolverContext{
|
||||
IndexContext: context,
|
||||
}
|
||||
resolver.Dependencies.Custom.Update(&ctx, r)
|
||||
|
||||
httpx.WriteHTML(ctx, nil, resolverTemplate, "", w, r)
|
||||
}
|
||||
p.TrustXForwardedProto = true
|
||||
|
||||
fallback := &resolvers.Regexp{
|
||||
|
|
|
|||
71
internal/dis/component/resolver/resolver.html
Normal file
71
internal/dis/component/resolver/resolver.html
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
{{ template "_base.html" . }}
|
||||
{{ define "title" }}WissKI Resolver{{ end }}
|
||||
|
||||
{{ define "header"}}
|
||||
<!-- no header -->
|
||||
{{ end }}
|
||||
|
||||
{{ define "content" }}
|
||||
<div class="pure-u-1">
|
||||
<h1>wdresolve</h1>
|
||||
<p>
|
||||
This page implements a resolver for the WissKI Distillery.
|
||||
It takes a <b>RDF / Triplestore URI</b> that refers to a <b>WissKI Entity</b> and redirects to the page that displays the entity.
|
||||
</p>
|
||||
</div>
|
||||
<div class="pure-u-1">
|
||||
<h2>Resolve URI</h2>
|
||||
<form action="." method="GET" class="pure-form" autocomplete="off">
|
||||
<label for="uri">Enter A URI To Resolve:</label>
|
||||
<input type="text" id="uri" name="uri" value="">
|
||||
<input type="submit" value="Resolve" class="pure-button pure-button-primary"/>
|
||||
|
||||
<p>
|
||||
You can also resolve a URI by a appending <code>?uri=</code> to the URL of this page, for example <code>{{ .URL }}?uri=graf://dr.acula/12345</code>.
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{{ if .Prefixes }}
|
||||
<div class="pure-u-1">
|
||||
<h2>Known Prefixes</h2>
|
||||
<p>
|
||||
These are for debugging purposes only.
|
||||
</p>
|
||||
</div>
|
||||
<div class="pure-u-1">
|
||||
<div class="padding">
|
||||
<div class="overflow">
|
||||
<table class="pure-table pure-table-bordered pure-form">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Prefix
|
||||
</th>
|
||||
<th>
|
||||
WissKI
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range $unused, $prefix := .Prefixes }}
|
||||
<tr>
|
||||
<td>
|
||||
<code>
|
||||
{{ (index $prefix 0) }}
|
||||
</code>
|
||||
</td>
|
||||
<td>
|
||||
<a href="{{ (index $prefix 1) }}" target="_blank" rel="noopener noreferrer" class="pure-button">
|
||||
{{ (index $prefix 1) }}
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
Loading…
Add table
Add a link
Reference in a new issue