Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22423118
render-site.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
render-site.js
View Options
const
bluebird
=
require
(
'bluebird'
);
const
colors
=
require
(
'colors'
);
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
util
=
require
(
'util'
);
const
exists
=
util
.
promisify
(
fs
.
exists
);
const
mkdir
=
util
.
promisify
(
fs
.
mkdir
);
const
writeFile
=
util
.
promisify
(
fs
.
writeFile
);
async
function
renderPage
(
page_content
,
file_path
)
{
const
dir
=
path
.
resolve
(
file_path
,
'..'
);
if
(
!
(
await
exists
(
dir
)))
{
await
mkdir
(
dir
,
{
recursive
:
true
});
}
await
writeFile
(
file_path
,
page_content
);
console
.
log
(
'rendered'
.
gray
,
file_path
.
green
);
}
async
function
renderSite
(
site_description
,
directory
)
{
await
bluebird
.
map
(
Object
.
keys
(
site_description
),
async
page_name
=>
{
if
(
!
(
site_description
[
page_name
]
instanceof
Function
))
{
throw
new
Error
(
'expected a function'
);
}
const
result
=
await
site_description
[
page_name
]();
typeof
result
===
'string'
?
await
renderPage
(
result
,
path
.
resolve
(
directory
,
`./
${
page_name
}
.html`
)
)
:
await
renderSite
(
result
,
path
.
resolve
(
directory
,
page_name
));
});
}
module
.
exports
=
renderSite
;
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Sat, Nov 28, 03:30 (1 d, 11 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1230188
Default Alt Text
render-site.js (1 KB)
Attached To
Mode
rSEALPAGE Sealpage
Attached
Detach File
Event Timeline