Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22391669
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
{
console
.
log
(
"CUSTOM URL VIEW"
);
if
(
ctx
.
body
)
return
;
console
.
log
(
"doesn't have body"
);
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
=
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
application/javascript
Expires
Fri, Nov 27, 15:41 (1 d, 5 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1227047
Default Alt Text
customUrlView.tsx (2 KB)
Attached To
Mode
rAPROXY Assetproxy
Attached
Detach File
Event Timeline