extract preview code into generatePreview
This commit is contained in:
parent
52382ba3a9
commit
cc8d2db6a3
|
@ -812,15 +812,7 @@ exports.publishView = () => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.previewView = ({authorMeta, text, contentWarning, blobId}) => {
|
const generatePreview = ({ authorMeta, text, contentWarning }) => {
|
||||||
if (typeof blobId !== "boolean") {
|
|
||||||
// TODO: filename?!
|
|
||||||
// TODO: mime type guessing for just link / !image / / audio: ?
|
|
||||||
text += "\n![your new blob]("+blobId+")"
|
|
||||||
}
|
|
||||||
|
|
||||||
const rawHtml = markdown(text);
|
|
||||||
|
|
||||||
// craft message that looks like it came from the db
|
// craft message that looks like it came from the db
|
||||||
const msg = {
|
const msg = {
|
||||||
key: "%non-existant.preview",
|
key: "%non-existant.preview",
|
||||||
|
@ -848,6 +840,29 @@ exports.previewView = ({authorMeta, text, contentWarning, blobId}) => {
|
||||||
const ago = Date.now() - Number(ts);
|
const ago = Date.now() - Number(ts);
|
||||||
const prettyAgo = prettyMs(ago, { compact: true });
|
const prettyAgo = prettyMs(ago, { compact: true });
|
||||||
lodash.set(msg, "value.meta.timestamp.received.since", prettyAgo);
|
lodash.set(msg, "value.meta.timestamp.received.since", prettyAgo);
|
||||||
|
return section({ class: "post-preview" },
|
||||||
|
post({msg}),
|
||||||
|
|
||||||
|
// doesn't need blobs, preview adds them to the text
|
||||||
|
form(
|
||||||
|
{ action: "/publish", method: "post" },
|
||||||
|
input({
|
||||||
|
name: "contentWarning",
|
||||||
|
type: "hidden",
|
||||||
|
value: contentWarning,
|
||||||
|
}),
|
||||||
|
input({
|
||||||
|
name: "text",
|
||||||
|
type: "hidden",
|
||||||
|
value: text,
|
||||||
|
}),
|
||||||
|
button({ type: "submit" }, i18n.publish),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.previewView = ({ authorMeta, text, contentWarning }) => {
|
||||||
|
const rawHtml = markdown(text);
|
||||||
|
|
||||||
return template(
|
return template(
|
||||||
i18n.preview,
|
i18n.preview,
|
||||||
|
@ -885,24 +900,11 @@ exports.previewView = ({authorMeta, text, contentWarning, blobId}) => {
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
button({ type: "submit" }, i18n.preview),
|
button({ type: "submit" }, i18n.preview),
|
||||||
),
|
label({ class: "file-button", for: "blob"}, "Attach files"),
|
||||||
|
input({ type: "file", id: "blob", name: "blob" })
|
||||||
// doesn't need blobs, preview adds them to the text
|
)
|
||||||
form(
|
|
||||||
{ action: "/publish", method: "post" },
|
|
||||||
input({
|
|
||||||
name: "contentWarning",
|
|
||||||
type: "hidden",
|
|
||||||
value: contentWarning,
|
|
||||||
}),
|
|
||||||
input({
|
|
||||||
name: "text",
|
|
||||||
type: "hidden",
|
|
||||||
value: text,
|
|
||||||
}),
|
|
||||||
button({ type: "submit" }, i18n.publish),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
generatePreview({ authorMeta, text, contentWarning }),
|
||||||
p(i18n.publishCustomInfo({ href: "/publish/custom" }))
|
p(i18n.publishCustomInfo({ href: "/publish/custom" }))
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue