Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F996294
customUrlView.tsx
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
customUrlView.tsx
View Options
import
type
{
Context
,
Next
}
from
"koa"
;
import
{
TempstreamJSX
}
from
"tempstream"
;
import
{
JDD
}
from
"@sealcode/jdd"
;
import
type
TheApp
from
"../../app.js"
;
import
{
registry
}
from
"../../jdd-components/components.js"
;
import
{
makeJDDContext
}
from
"../../jdd-context.js"
;
import
type
{
RawJDDocument
}
from
"@sealcode/jdd"
;
import
{
imageRouter
}
from
"../../image-router.js"
;
import
type
{
FilePointer
}
from
"@sealcode/file-manager"
;
import
html
from
"../../html.js"
;
import
{
tempstream
}
from
"tempstream"
;
import
{
defaultHead
}
from
"../../defaultHead.js"
;
import
{
BASE_URL
}
from
"../../config.js"
;
interface
ContextState
{
jddNames
:
string
[];
}
/* eslint-disable @typescript-eslint/consistent-type-assertions */
export
const
customUrlView
=
(
app
:
TheApp
)
=>
async
(
ctx
:
Context
&
ContextState
,
next
:
Next
)
=>
{
try
{
if
(
ctx
.
body
)
return
;
const
main_domain
=
new
URL
(
BASE_URL
).
hostname
;
const
{
items
:
[
page
],
}
=
await
app
.
collections
.
page
.
list
(
ctx
.
$context
)
.
filter
({
url
:
ctx
.
url
.
split
(
"?"
)[
0
],
...(
ctx
.
hostname
!==
main_domain
?
{
domain
:
ctx
.
hostname
}
:
{
domain
:
""
}),
})
.
fetch
();
const
pageContent
=
Array
.
isArray
(
page
?
.
get
(
"content"
))
?
(
page
?
.
get
(
"content"
)
as
RawJDDocument
)
:
null
;
if
(
page
&&
pageContent
)
{
const
jdd
=
await
JDD
.
fromStorage
(
registry
,
makeJDDContext
(
ctx
),
pageContent
);
const
title
=
page
.
get
(
"title"
);
const
heading
=
page
.
get
(
"heading"
);
const
hideNavigation
=
page
.
get
(
"hideNavigation"
)
||
false
;
ctx
.
body
=
html
({
ctx
,
title
:
title
||
"Aspazja"
,
description
:
page
.
get
(
"description"
)
||
""
,
css_clumps
:
jdd
.
getAllCSSClumps
(),
hideNavigation
,
htmlOptions
:
{
showFooter
:
!
hideNavigation
,
},
body
:
(
<
main
class
=
"custom-page jdd-outer-container"
>
{
heading
?
.
trim
()
?
<
h1
>
{
heading
}
<
/h1> : ""}
<
div
class
=
"jdd-container"
>
{
jdd
.
render
()}
<
/div>
<
/main>
),
makeHead
:
(...
args
)
=>
tempstream
`
${
defaultHead
(...
args
)
}${
jdd
.
renderEarlyAssets
()
}
`
,
metaImage
:
await
imageRouter
.
singleImage
(
await
(
page
.
get
(
"imageForMetadata"
)
as
FilePointer
).
getPath
(),
400
,
"jpeg"
,
false
),
});
}
}
catch
(
err
)
{
// eslint-disable-next-line no-console
console
.
log
(
"error in custom url router middleware:"
,
err
);
}
finally
{
await
next
();
}
};
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Tue, Dec 24, 14:02 (16 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
556582
Default Alt Text
customUrlView.tsx (2 KB)
Attached To
Mode
rREWRITE Configurable rewriter
Attached
Detach File
Event Timeline
Log In to Comment