Skip to content

Commit

Permalink
Show hidden posts in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dallyh committed Feb 22, 2024
1 parent 9a53bcd commit 479127f
Show file tree
Hide file tree
Showing 22 changed files with 68 additions and 53 deletions.
12 changes: 12 additions & 0 deletions src/components/astro/blog/BlogPostPreview.astro
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ await loadNamespaces(locale, ["blog"]);
---

<div class="post-preview">
{post.data.hidden && <div class="hidden-post">DEV MODE HIDDEN</div>}
<img src={ogUrl} alt={post.data.title} loading="eager" />
<hr />
<div class="post-description">
Expand All @@ -43,6 +44,16 @@ await loadNamespaces(locale, ["blog"]);
</div>

<style>
.hidden-post {
color: red;
position: absolute;
font-weight: 600;
font-size: 3rem;
opacity: 0.2;
top: 50%;
transform: translateY(-50%) rotate(45deg);
}

.post-preview {
display: flex;
flex-direction: column;
Expand All @@ -56,6 +67,7 @@ await loadNamespaces(locale, ["blog"]);
overflow: hidden;
color: var(--body-color);
border: var(--border);
position: relative;

.tags {
display: flex;
Expand Down
13 changes: 13 additions & 0 deletions src/components/astro/blog/SmallBlogPostPreview.astro
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ await loadNamespaces(locale, ["blog"]);
---

<div class="post-preview">
{post.data.hidden && <div class="hidden-post">DEV MODE HIDDEN</div>}
<img src={ogUrl} alt={post.data.title} />
<div class="post-description">
<a href={postUrl} class="post-title">{post.data.title}</a>
Expand All @@ -37,6 +38,17 @@ await loadNamespaces(locale, ["blog"]);
</div>

<style>
.hidden-post {
color: red;
position: absolute;
font-weight: 600;
font-size: 3rem;
opacity: 0.2;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
}

.post-preview {
display: flex;
flex-direction: row;
Expand All @@ -48,6 +60,7 @@ await loadNamespaces(locale, ["blog"]);
overflow: hidden;
color: var(--body-color);
border: var(--border);
position: relative;

@media (max-width: 468px) {
flex-direction: column;
Expand Down
8 changes: 8 additions & 0 deletions src/content/categories/other.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
id: other
languages:
cs:
title: Nezařazeno
description: Ostatní a nezařazené příspěvky.
en:
title: Uncategorized
description: Other and uncategorized posts.
2 changes: 1 addition & 1 deletion src/content/posts/cs/2023-01-01-my-fourth-blog-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tags:
- astro
- development
- flexicapture
hidden: false
hidden: true
category: guides
---

Expand Down
2 changes: 1 addition & 1 deletion src/content/posts/cs/2023-01-01-my-second-blog-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ tags:
- astro
- development
- flexicapture
hidden: false
hidden: true
featured: true
pubDateTime: 2024-01-04T14:10:16+01:00
modDatetime: ""
Expand Down
2 changes: 1 addition & 1 deletion src/content/posts/cs/2023-01-01-my-third-blog-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tags:
- astro
- development
- flexicapture
hidden: false
hidden: true
---

This is a paragraph. Lorem ipsum dolor sit amet consectetur adipisicing elit. Tenetur vero esse non molestias eos excepturi, inventore atque cupiditate. Sed voluptatem quas omnis culpa, et odit.
Expand Down
1 change: 1 addition & 0 deletions src/content/posts/cs/2023-01-01-typography-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ image:
tags:
- astro
hidden: false
category: other
---

This is a paragraph. Lorem ipsum dolor sit amet consectetur adipisicing elit. Tenetur vero esse non molestias eos excepturi, inventore atque cupiditate. Sed voluptatem quas omnis culpa, et odit.
Expand Down
2 changes: 1 addition & 1 deletion src/content/posts/cs/2023-12-29-localized-slug-title.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ author: Dalibor Hon
tags:
- flexicapture
language: cs
hidden: false
hidden: true
featured: true
pubDateTime: 2023-12-29T23:20:35.541
---
Expand Down
15 changes: 0 additions & 15 deletions src/content/posts/cs/2024-01-02-test-post-from-identity.md

This file was deleted.

2 changes: 1 addition & 1 deletion src/content/posts/cs/2024-01-07-test-post-from-cms.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tags:
- flexicapture
category: software
language: cs
hidden: false
hidden: true
featured: false
ogImage: /assets/uploads/img/astro.jpg
pubDateTime: 2024-01-07T21:37:39+01:00
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tags:
- development
category: software
language: cs
hidden: false
hidden: true
featured: false
ogImage: https://astro.build/og/astro.jpg
pubDateTime: 2024-01-13T22:09:12+01:00
Expand Down
2 changes: 1 addition & 1 deletion src/content/posts/en/2023-01-01-my-fourth-blog-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tags:
- astro
- development
- flexicapture
hidden: false
hidden: true
category: guides
---

Expand Down
2 changes: 1 addition & 1 deletion src/content/posts/en/2023-01-01-my-second-blog-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ tags:
- astro
- development
- flexicapture
hidden: false
hidden: true
featured: true
pubDateTime: 2024-01-04T14:10:16+01:00
modDatetime: ""
Expand Down
2 changes: 1 addition & 1 deletion src/content/posts/en/2023-01-01-my-third-blog-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tags:
- astro
- development
- flexicapture
hidden: false
hidden: true
---

This is a paragraph. Lorem ipsum dolor sit amet consectetur adipisicing elit. Tenetur vero esse non molestias eos excepturi, inventore atque cupiditate. Sed voluptatem quas omnis culpa, et odit.
Expand Down
1 change: 1 addition & 0 deletions src/content/posts/en/2023-01-01-typography-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ image:
tags:
- astro
hidden: false
category: other
---

This is a paragraph. Lorem ipsum dolor sit amet consectetur adipisicing elit. Tenetur vero esse non molestias eos excepturi, inventore atque cupiditate. Sed voluptatem quas omnis culpa, et odit.
Expand Down
2 changes: 1 addition & 1 deletion src/content/posts/en/2023-12-29-localized-slug-title.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ author: Dalibor Hon
tags:
- flexicapture
language: en
hidden: false
hidden: true
featured: true
pubDateTime: 2023-12-29T23:20:35.541
---
Expand Down
15 changes: 0 additions & 15 deletions src/content/posts/en/2024-01-02-test-post-from-identity.md

This file was deleted.

2 changes: 1 addition & 1 deletion src/content/posts/en/2024-01-07-test-post-from-cms.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tags:
- flexicapture
category: software
language: en
hidden: false
hidden: true
featured: false
ogImage: /assets/uploads/img/astro.jpg
pubDateTime: 2024-01-07T21:37:39+01:00
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tags:
- development
category: software
language: en
hidden: false
hidden: true
featured: false
ogImage: https://astro.build/og/astro.jpg
pubDateTime: 2024-01-13T22:09:12+01:00
Expand Down
6 changes: 3 additions & 3 deletions src/pages/[...lang]/blog/categories/[...category].astro
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export async function getStaticPaths() {
const paths = await Promise.all(categories.flatMap((cat) => {
return locales.map(async (locale) => {
const filteredPosts = await getFilteredPostsCollection({ locale: locale, categoryId: category });
if (filteredPosts?.length === 0) {
const filteredPosts = await getFilteredPostsCollection({ locale: locale, categoryId: cat.id });
if (filteredPosts === undefined || filteredPosts.length === 0) {
return { params: { lang: getRoutingLocale(locale), category: undefined } }
}
Expand Down
11 changes: 5 additions & 6 deletions src/pages/[...lang]/blog/posts/[...slug]/index.png.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { defaultLocale } from "@config/i18n";
import { getRoutingLocale } from "@i18n/utils";
import { generateOgImageForPost, getBlogPostSlug } from "@utils";
import { generateOgImageForPost, getBlogPostSlug, getFilteredPostsCollection } from "@utils";
import type { APIContext } from "astro";
import { getCollection, type CollectionEntry } from "astro:content";
import {type CollectionEntry } from "astro:content";

export async function getStaticPaths() {
const allPosts = await getCollection("posts", ({ data }) => {
return !data.hidden;
});
const paths = allPosts.map((post) => {
const allPosts = await getFilteredPostsCollection();

const paths = allPosts?.map((post) => {
return { params: { lang: getRoutingLocale(post.data.language), slug: getBlogPostSlug(post.data.language, post) }, props: { post: post } };
});

Expand Down
15 changes: 13 additions & 2 deletions src/utils/getFilteredPostsCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ interface FilteredPostsOptions {
tagId?: string;
}

export async function getFilteredPostsCollection(options: FilteredPostsOptions) {
export async function getFilteredPostsCollection(options: FilteredPostsOptions | undefined = undefined) {
if (options === undefined) {
return await getCollection("posts");
}

const { featured, sort, locale, slice, categoryId, tagId } = options;

let posts = await getCollection("posts", ({ data }) => {
Expand Down Expand Up @@ -46,7 +50,14 @@ function buildCondition(data: any, options: BuildConditionOptions = {}) {
const { featured, locale, categoryId, tagId } = options;

// Basic condition
let condition: boolean = !data.hidden;
let condition: boolean

// In DEV mode, show all posts
if (import.meta.env.DEV) {
condition = true;
} else {
condition = !data.hidden;
}

if (locale) {
condition = condition && data.language === locale;
Expand Down

0 comments on commit 479127f

Please sign in to comment.