New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scheduled posts #26
Comments
My thoughts on keeping this fairly generic:
Webtask even has a simple-to-setup web interface for managing fxns, so this could totally be implemented a plugin with front-to-back support. The only part that isn't handled for the user is trigger their build process, because that would be different for everyone. |
This repository is now using lodash style issue management for enhancements (see https://twitter.com/samselikoff/status/991395669016436736) This means enhancement issues will now be closed instead of leaving them open. The enhancement backlog can be found here: https://github.com/11ty/eleventy/issues?utf8=%E2%9C%93&q=label%3Aneeds-votes+sort%3Areactions-%2B1-desc+ |
+1 |
@cmaxw I believe you need to use a GitHub emoji on the initial post to make your vote count. @cferdinandi I was wondering, whether I could use a future date + collection to control the showing up of a file. But I believe that would still make it render (personally, I'm keeping my drafts outside of the directory used for eleventy to render …). Will try some things out and let you know how it went. |
I got you... I figured it out... See https://github.com/cmaxw/devchat-eleventy/blob/4d59ef949e36f55b2b9cb1af84a809a7cfcefcc7/.eleventy.js#L56 Specifically, I create my own filters that filter on date... |
Bonus points if you move the left hand side of https://github.com/cmaxw/devchat-eleventy/blob/4d59ef949e36f55b2b9cb1af84a809a7cfcefcc7/.eleventy.js#L61 out of the filter to save some milliseconds (because you only need to have that information once for comparison). Line 57 is fine. |
@Ryuno-Ki The left hand side? or the right hand side? Or in other words, the part where I pull the date on the podcast entry? or the part where I calculate the current date/time with moment? I can see calculating the date with moment once and then using that value for the rest of the work. |
This. Ah, but |
I used to use this snippet from Remy but I think it only removes the post from collections—it doesn't set its I've been thinking of using a snippet like this instead. It doesn't do scheduled posts at the moment, though that would be easy to add. module.exports = {
eleventyComputed: {
/**
* Adds support for drafts.
* If a page has `draft: true` in its YAML frontmatter then this snippet
* will set its permalink to false and exclude it from collections.
*
* For dev builds we will always render the page.
*/
permalink: data => {
if (process.env.NODE_ENV === 'production' && data.draft) {
return false;
}
return data.permalink;
},
eleventyExcludeFromCollections: data => {
if (process.env.NODE_ENV === 'production' && data.draft) {
return true;
}
return false;
}
}
} |
@robdodson, thanks for sharing this. This is exactly what I am looking for. |
@robdodson Thanks for this! I was able to get scheduled posts working using your computed data file (with the addition of checking dates) and automating daily builds with GitHub Actions.
module.exports = {
eleventyComputed: {
/**
* Handle drafts and scheduled posts
* https://github.com/11ty/eleventy/issues/26#issuecomment-791993563
*
* For production mode, if a post has `draft: true` in its YAML
* frontmatter or it has a future date, then this snippet will set
* `permalink: false` and exclude it from collections. This prevents the
* post from being built.
*
* The actual publishing (aka building) of scheduled posts is handled
* by GitHub Actions’ cron feature, which runs daily at 00:00 UTC.
*
* For dev mode, always render all posts.
*/
permalink: data => {
if (process.env.NODE_ENV === 'production' && (data.draft || data.page.date >= new Date())) {
return false;
}
return data.permalink;
},
eleventyExcludeFromCollections: data => {
if (process.env.NODE_ENV === 'production' && (data.draft || data.page.date >= new Date())) {
return true;
}
return false;
}
}
}
name: Build Eleventy
on:
push:
branches:
- master
schedule:
- cron: '0 0 * * *' # every day at 00:00 UTC
jobs:
build:
runs-on: ubuntu-20.04
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies & build
run: |
npm ci
npm run build
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
publish_dir: ./public
github_token: ${{ secrets.GITHUB_TOKEN }} |
One of the big things that keeps me away from static site generators is the ability to schedule posts to go live at a future date/time.
I know it's a bit complicated, but I would a way to schedule posts in advance (even if it's just documentation on setting up the right continuous deployment script or something).
The text was updated successfully, but these errors were encountered: