mirror of
https://github.com/ipfs/ipfs-blog.git
synced 2026-08-07 09:22:44 +02:00
Merge pull request #157 from ipfs/feat/hide-future-posts
Hide future posts/links and auto publish them on speficied date
This commit is contained in:
@@ -1,4 +1,32 @@
|
||||
const slug = require('slug')
|
||||
const dayjs = require('dayjs')
|
||||
|
||||
function shouldBeHidden(frontmatter) {
|
||||
const isDateInFuture = (date) => dayjs(new Date(date)).isAfter(dayjs())
|
||||
let shouldHide = frontmatter.hidden || false
|
||||
|
||||
// sitemap config
|
||||
if (frontmatter.sitemap) {
|
||||
shouldHide = shouldHide || frontmatter.sitemap.exclude
|
||||
}
|
||||
|
||||
// scheduled posts
|
||||
// see auto-publishing of scheduled posts here: https://github.com/ipfs/ipfs-blog/issues/147
|
||||
if (
|
||||
!shouldHide &&
|
||||
frontmatter.permalink && // permalink is unique to posts
|
||||
frontmatter.date
|
||||
) {
|
||||
shouldHide = shouldHide || isDateInFuture(frontmatter.date)
|
||||
}
|
||||
|
||||
// scheduled links (path is unique to links)
|
||||
if (!shouldHide && frontmatter.path && frontmatter.publish_date) {
|
||||
shouldHide = shouldHide || isDateInFuture(frontmatter.publish_date)
|
||||
}
|
||||
|
||||
return shouldHide
|
||||
}
|
||||
|
||||
module.exports = (options, context) => ({
|
||||
extendPageData($page) {
|
||||
@@ -18,8 +46,8 @@ module.exports = (options, context) => ({
|
||||
frontmatter.authorKey = authorKey
|
||||
}
|
||||
|
||||
// exclude a page from the feed & robots if excluded from sitemap
|
||||
if (frontmatter.sitemap && frontmatter.sitemap.exclude) {
|
||||
// exclude hidden pages (sitemap config, future publishes, etc)
|
||||
if (shouldBeHidden(frontmatter)) {
|
||||
frontmatter.feed = {
|
||||
enable: false,
|
||||
}
|
||||
@@ -30,6 +58,18 @@ module.exports = (options, context) => ({
|
||||
} else {
|
||||
frontmatter.meta = [noIndex]
|
||||
}
|
||||
|
||||
frontmatter.hidden = true
|
||||
$page.hidden = true
|
||||
}
|
||||
|
||||
// set links has hidden (future publishes, etc)
|
||||
if (frontmatter.data) {
|
||||
frontmatter.data.forEach((item) => {
|
||||
if (shouldBeHidden(item)) {
|
||||
item.hidden = true
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -129,14 +129,8 @@ export default {
|
||||
return false
|
||||
}
|
||||
|
||||
if (
|
||||
page.frontmatter &&
|
||||
(page.frontmatter.sitemap ? !page.frontmatter.sitemap.exclude : true)
|
||||
) {
|
||||
result.push({
|
||||
...page,
|
||||
category: defaultCategory,
|
||||
})
|
||||
if (page.frontmatter && !page.frontmatter.hidden) {
|
||||
result.push({ ...page, category: defaultCategory })
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<Layout v-if="!$frontmatter.type">
|
||||
<Layout v-if="isVisible">
|
||||
<article itemscope itemtype="https://schema.org/BlogPosting">
|
||||
<PostHero
|
||||
:title="$page.title"
|
||||
@@ -46,7 +46,18 @@ export default {
|
||||
data: () => ({
|
||||
showComments: null,
|
||||
}),
|
||||
computed: {
|
||||
// hidden field set in plugins/pageData.js
|
||||
isVisible() {
|
||||
return !this.$root.$page.hidden
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
if (!this.isVisible) {
|
||||
// path to 404 is relative to support ipfs sub path deployments
|
||||
return this.$router.replace({ path: '../404' })
|
||||
}
|
||||
|
||||
const ipfsPathRegExp = /^(\/(?:ipfs|ipns)\/[^/]+)/
|
||||
const ipfsPathPrefix =
|
||||
(window.location.pathname.match(ipfsPathRegExp) || [])[1] || ''
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export const checkItem = ({
|
||||
export function checkItem({
|
||||
postType,
|
||||
tags,
|
||||
title,
|
||||
@@ -7,7 +7,7 @@ export const checkItem = ({
|
||||
searchedText = [],
|
||||
activeCategory = '',
|
||||
activeAuthor = '',
|
||||
}) => {
|
||||
}) {
|
||||
if (activeCategory && decodeURI(activeCategory) !== postType) {
|
||||
return false
|
||||
}
|
||||
@@ -40,13 +40,13 @@ export const checkItem = ({
|
||||
return true
|
||||
}
|
||||
|
||||
export const parseProtectedPost = (
|
||||
export function parseProtectedPost(
|
||||
post,
|
||||
activeTags = [],
|
||||
searchedText = [],
|
||||
activeCategory = '',
|
||||
activeAuthor = ''
|
||||
) => {
|
||||
) {
|
||||
if (!post.frontmatter.data) {
|
||||
return []
|
||||
}
|
||||
@@ -55,6 +55,7 @@ export const parseProtectedPost = (
|
||||
|
||||
post.frontmatter.data.forEach((item) => {
|
||||
if (
|
||||
item.hidden ||
|
||||
!checkItem({
|
||||
postType: post.frontmatter.type,
|
||||
tags: item.tags,
|
||||
|
||||
@@ -7,6 +7,7 @@ author: Dietrich Ayala
|
||||
header_image: "/086-ipfs-in-opera-for-android-header-image.png"
|
||||
tags:
|
||||
- browsers
|
||||
- opera
|
||||
- mobile
|
||||
|
||||
---
|
||||
|
||||
@@ -6,7 +6,6 @@ sitemap:
|
||||
data:
|
||||
- title: IPFS Community Meetup, April 2021
|
||||
date: 2021-04-27
|
||||
publishing_date:
|
||||
path: https://www.meetup.com/San-Francisco-IPFS/events/276123324/
|
||||
card_image: "/2021-04-15-cardheader-ipfs-meetup-nft-april2021.png"
|
||||
tags:
|
||||
@@ -14,7 +13,6 @@ data:
|
||||
- official meetup
|
||||
- title: Cal Hacks hello:world
|
||||
date: 2021-04-16
|
||||
publishing_date: 2021-04-15 17:06:47 +0000
|
||||
path: https://helloworld.calhacks.io/
|
||||
card_image: "/2021-04-15-cardheader-hello-world.png"
|
||||
tags:
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
---
|
||||
publishing_date:
|
||||
title: Welcome to IPFS Weekly 131
|
||||
description: Uniswap Interface hosting on IPFS, a call for Filecoin user testers,
|
||||
and more from around the ecosystem!
|
||||
|
||||
Reference in New Issue
Block a user