Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22421403
customUrlView.tsx
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
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
.
pages
.
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_context
=
makeJDDContext
(
ctx
);
const
jdd
=
await
JDD
.
fromStorage
(
registry
,
jdd_context
,
pageContent
);
const
title
=
page
.
get
(
"title"
);
const
heading
=
page
.
get
(
"heading"
);
const
hideNavigation
=
page
.
get
(
"hideNavigation"
)
||
false
;
const
metaImage
=
(
page
.
get
(
"imageForMetadata"
)
as
FilePointer
)
||
undefined
;
ctx
.
body
=
html
({
ctx
,
title
:
title
||
ctx
.
$app
.
manifest
.
name
,
description
:
page
.
get
(
"description"
)
||
""
,
css_clumps
:
jdd
.
getAllCSSClumps
(
jdd_context
),
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
:
metaImage
?
await
imageRouter
.
singleImage
(
await
metaImage
.
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
application/javascript
Expires
Sat, Nov 28, 03:09 (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1217824
Default Alt Text
customUrlView.tsx (2 KB)
Attached To
Mode
rAPROXY Assetproxy
Attached
Detach File
Event Timeline