resolver: Use custom template
This commit is contained in:
parent
a292c25f84
commit
729b9cfb51
4 changed files with 102 additions and 6 deletions
4
go.mod
4
go.mod
|
|
@ -3,7 +3,7 @@ module github.com/FAU-CDI/wisski-distillery
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/FAU-CDI/wdresolve v0.0.0-20220911200729-e66b93ed2b69
|
github.com/FAU-CDI/wdresolve v0.0.0-20230108072141-c9c6779d7c41
|
||||||
github.com/Showmax/go-fqdn v1.0.0
|
github.com/Showmax/go-fqdn v1.0.0
|
||||||
github.com/alessio/shellescape v1.4.1
|
github.com/alessio/shellescape v1.4.1
|
||||||
github.com/feiin/sqlstring v0.3.0
|
github.com/feiin/sqlstring v0.3.0
|
||||||
|
|
@ -20,7 +20,7 @@ require (
|
||||||
github.com/tdewolff/minify v2.3.6+incompatible
|
github.com/tdewolff/minify v2.3.6+incompatible
|
||||||
github.com/tkw1536/goprogram v0.2.4
|
github.com/tkw1536/goprogram v0.2.4
|
||||||
golang.org/x/crypto v0.3.0
|
golang.org/x/crypto v0.3.0
|
||||||
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db
|
golang.org/x/exp v0.0.0-20230105202349-8879d0199aa3
|
||||||
golang.org/x/sync v0.1.0
|
golang.org/x/sync v0.1.0
|
||||||
golang.org/x/term v0.3.0
|
golang.org/x/term v0.3.0
|
||||||
gorm.io/driver/mysql v1.4.4
|
gorm.io/driver/mysql v1.4.4
|
||||||
|
|
|
||||||
8
go.sum
8
go.sum
|
|
@ -1,5 +1,5 @@
|
||||||
github.com/FAU-CDI/wdresolve v0.0.0-20220911200729-e66b93ed2b69 h1:wjiRzjx8G7Vm/rqHuAv9qMeLNHV3RmO9SNkh8VrvsBQ=
|
github.com/FAU-CDI/wdresolve v0.0.0-20230108072141-c9c6779d7c41 h1:RRN/aPFEOSpQVcq+f0iTBkUt6L/EBPTSH9risO3SDto=
|
||||||
github.com/FAU-CDI/wdresolve v0.0.0-20220911200729-e66b93ed2b69/go.mod h1:9L2AZlOgDtg1WZ9Z1P1nBjqOY/b0mVrVE7UvO20pO2Q=
|
github.com/FAU-CDI/wdresolve v0.0.0-20230108072141-c9c6779d7c41/go.mod h1:9L2AZlOgDtg1WZ9Z1P1nBjqOY/b0mVrVE7UvO20pO2Q=
|
||||||
github.com/Showmax/go-fqdn v1.0.0 h1:0rG5IbmVliNT5O19Mfuvna9LL7zlHyRfsSvBPZmF9tM=
|
github.com/Showmax/go-fqdn v1.0.0 h1:0rG5IbmVliNT5O19Mfuvna9LL7zlHyRfsSvBPZmF9tM=
|
||||||
github.com/Showmax/go-fqdn v1.0.0/go.mod h1:SfrFBzmDCtCGrnHhoDjuvFnKsWjEQX/Q9ARZvOrJAko=
|
github.com/Showmax/go-fqdn v1.0.0/go.mod h1:SfrFBzmDCtCGrnHhoDjuvFnKsWjEQX/Q9ARZvOrJAko=
|
||||||
github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0=
|
github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0=
|
||||||
|
|
@ -68,8 +68,8 @@ github.com/tkw1536/goprogram v0.2.4/go.mod h1:3Ngcwy7jtsZ+pINc+JfLdf8TWbvthdSS2T
|
||||||
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A=
|
golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A=
|
||||||
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
||||||
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db h1:D/cFflL63o2KSLJIwjlcIt8PR064j/xsmdEJL/YvY/o=
|
golang.org/x/exp v0.0.0-20230105202349-8879d0199aa3 h1:fJwx88sMf5RXwDwziL0/Mn9Wqs+efMSo/RYcL+37W9c=
|
||||||
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
|
golang.org/x/exp v0.0.0-20230105202349-8879d0199aa3/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
|
||||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
|
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
|
||||||
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
||||||
|
|
|
||||||
|
|
@ -10,15 +10,21 @@ import (
|
||||||
"github.com/FAU-CDI/wdresolve"
|
"github.com/FAU-CDI/wdresolve"
|
||||||
"github.com/FAU-CDI/wdresolve/resolvers"
|
"github.com/FAU-CDI/wdresolve/resolvers"
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
"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/internal/dis/component/instances"
|
||||||
|
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
|
||||||
"github.com/FAU-CDI/wisski-distillery/pkg/lazy"
|
"github.com/FAU-CDI/wisski-distillery/pkg/lazy"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
|
|
||||||
|
_ "embed"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Resolver struct {
|
type Resolver struct {
|
||||||
component.Base
|
component.Base
|
||||||
Dependencies struct {
|
Dependencies struct {
|
||||||
Instances *instances.Instances
|
Instances *instances.Instances
|
||||||
|
Custom *custom.Custom
|
||||||
}
|
}
|
||||||
|
|
||||||
prefixes lazy.Lazy[map[string]string] // cached prefixes (from the server)
|
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) {
|
func (resolver *Resolver) HandleRoute(ctx context.Context, route string) (http.Handler, error) {
|
||||||
|
resolverTemplate := resolver.Dependencies.Custom.Template(resolverTemplate)
|
||||||
|
|
||||||
logger := zerolog.Ctx(ctx)
|
logger := zerolog.Ctx(ctx)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
return resolver.handler.Get(func() (p wdresolve.ResolveHandler) {
|
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
|
p.TrustXForwardedProto = true
|
||||||
|
|
||||||
fallback := &resolvers.Regexp{
|
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