-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add files' option to publish or save as draft
Allows publishing pages and posts right away or save to publish later
- Loading branch information
Showing
14 changed files
with
159 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { getPages, getPosts, prevNext } from "../../functions/blog-doc.js" | ||
import { initializeApp } from "../../functions/initialize.js" | ||
import { idsInHeadings } from "../../functions/helpers.js" | ||
import { getSettings } from "../../functions/settings.js" | ||
import { marked } from "marked" | ||
|
||
const { eta } = initializeApp() | ||
|
||
// Markdown Route | ||
export function adminPreviewRoute(app) { | ||
/** | ||
* Due to Velocy architecture, a route without a defined start point cannot be reached. | ||
* This is why two routes are created, one for the pages and the other for posts. | ||
* In short, the following route "/:folder/:filename" doesn't work in Velocy. | ||
*/ | ||
app.get("/admin-preview-page/:filename", async (req, res) => { | ||
const settings = await getSettings() | ||
|
||
const pages = await getPages() | ||
const unpublishedPages = pages.filter((page) => page[1].frontmatter.published == "false") | ||
const currentFile = unpublishedPages.find((file) => file.path === `pages/${req.params.filename}.md`) | ||
|
||
if (currentFile) { | ||
const fileData = currentFile[1].frontmatter | ||
fileData.favicon = settings.favicon | ||
const fileContent = marked.parse(currentFile[1].content) | ||
const response = eta.render(`themes/${settings.currentTheme}/layouts/base.html`, { | ||
// Passing Route data | ||
mdRoute: true, | ||
// Passing Markdown file data | ||
data: fileData, | ||
content: settings.addIdsToHeadings ? idsInHeadings(fileContent) : fileContent, | ||
// Passing data to edit the file | ||
editable: true, | ||
filename: req.params.filename, | ||
// Passing needed settings for the template | ||
siteTitle: settings.siteTitle, | ||
menuLinks: settings.menuLinks, | ||
footerCopyright: settings.footerCopyright, | ||
}) | ||
res.writeHead(200, { "Content-Type": "text/html" }) | ||
res.end(response) | ||
} else { | ||
// Proceed to the 404 route if no file is found | ||
res.writeHead(302, { Location: "/404" }) | ||
res.end() | ||
} | ||
}) | ||
|
||
app.get("/admin-preview-post/:filename", async (req, res) => { | ||
const settings = await getSettings() | ||
|
||
const posts = await getPosts() | ||
const unpublishedPosts = posts.filter((post) => post[1].frontmatter.published == "false") | ||
const currentFile = unpublishedPosts.find((file) => file.path === `posts/${req.params.filename}.md`) | ||
|
||
if (currentFile) { | ||
const fileData = currentFile[1].frontmatter | ||
fileData.favicon = settings.favicon | ||
const fileContent = marked.parse(currentFile[1].content) | ||
const response = eta.render(`themes/${settings.currentTheme}/layouts/base.html`, { | ||
// Passing Route data | ||
mdRoute: true, | ||
// Passing Markdown file data | ||
data: fileData, | ||
content: settings.addIdsToHeadings ? idsInHeadings(fileContent) : fileContent, | ||
prevNext: currentFile.dir === "posts" ? await prevNext(`${req.params.filename}.md`) : null, | ||
// Passing data to edit the file | ||
editable: true, | ||
filename: req.params.filename, | ||
// Passing needed settings for the template | ||
siteTitle: settings.siteTitle, | ||
menuLinks: settings.menuLinks, | ||
footerCopyright: settings.footerCopyright, | ||
}) | ||
res.writeHead(200, { "Content-Type": "text/html" }) | ||
res.end(response) | ||
} else { | ||
// Proceed to the 404 route if no file is found | ||
res.writeHead(302, { Location: "/404" }) | ||
res.end() | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<% /* Since v5.3.0 to allow publishing now or later */ %> | ||
<div class="mb-3"> | ||
<label for="publish-select" class="form-label"> | ||
<b>Publish* - REQUIRED!</b> | ||
</label> | ||
|
||
<select id="publish-select" name="published" class="form-select" required> | ||
<option value="">Please choose an option</option> | ||
<% if (it.adminCreate) { %> | ||
<option value="true" selected>True</option> | ||
<option value="false">False</option> | ||
<% } else { %> | ||
<!-- Start adminUpdate publish select --> | ||
<% const published = JSON.parse(it.file[1].frontmatter.published) %> | ||
<!-- Published value to string --> | ||
<% const publishedString = JSON.stringify(published) %> | ||
<!-- Published contrary value to string --> | ||
<% const publishedContraryString = JSON.stringify(!published) %> | ||
|
||
<option value="<%= published %>" selected> | ||
<%= publishedString.charAt(0).toUpperCase() + publishedString.slice(1) %> | ||
</option> | ||
|
||
<option value="<%= !published %>"> | ||
<%= publishedContraryString.charAt(0).toUpperCase() + publishedContraryString.slice(1) %> | ||
</option> | ||
<!-- End adminUpdate publish select --> | ||
<% } %> | ||
</select> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters