Skip to content

Commit

Permalink
Merge pull request #652 from fey/revert-fix-hidden-posts
Browse files Browse the repository at this point in the history
Revert "Merge pull request #647 from Ledchig/fix-hidden-posts"
  • Loading branch information
fey authored Mar 13, 2024
2 parents 4da553d + b475c57 commit 22a6866
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const makePostRSSItem = async (post, locale) => {
};
};

export const getPosts = async (locale) => {
export const getPublishedPosts = async (locale) => {
const dir = process.cwd();
const postsPath = path.join('data', 'posts', locale);
const entries = await fsp.readdir(path.join(dir, postsPath), { withFileTypes: true });
Expand All @@ -124,18 +124,18 @@ export const getPosts = async (locale) => {
const promises = fileNames
.sort((a, b) => a.localeCompare(b))
.map(async (name) => readPost(path.join(postsPath, name), dir, locale));

return await Promise.all(promises);
};

export const getPostsList = async (locale) => {
const posts = await getPosts(locale);
const posts = await getPublishedPosts(locale);

return posts.filter(({ hidden = false }) => !hidden).reverse();
};

export const findPost = async (name, locale) => {
const posts = await getPostsList(locale);
const posts = await getPublishedPosts(locale);
const postIndex = findLastIndex(posts, (post) => post.name === name);

if (postIndex === -1) {
Expand All @@ -157,7 +157,7 @@ export const findPost = async (name, locale) => {
};

export const generateRssFeed = async (locale) => {
const posts = await getPosts(locale);
const posts = await getPublishedPosts(locale);
const promises = posts.filter(({ hidden = false }) => !hidden).map((post) => makePostRSSItem(post, locale));

const feedItems = await Promise.all(promises);
Expand All @@ -174,7 +174,7 @@ export const generateRssFeed = async (locale) => {
};

export const generateSitemap = async (locale) => {
const posts = await getPosts(locale);
const posts = await getPublishedPosts(locale);
const visiblePosts = posts.filter(({ hidden = false }) => !hidden);
const fields = visiblePosts.map((post) => ({
loc: new URL(path.join(post.href, '/'), cfg.siteURL),
Expand Down Expand Up @@ -234,7 +234,7 @@ export const getPostAwailableLocales = async (name, locale, locales) => {
/// Getting posts from another locales
const promises = locales
.filter((l) => l !== locale)
.map(async (loc) => ({ loc, posts : await getPosts(loc) }));
.map(async (loc) => ({ loc, posts : await getPublishedPosts(loc) }));
const anotherPosts = await Promise.all(promises);
/// Searching for translated posts to original post
const awailableLocales = anotherPosts
Expand Down
4 changes: 2 additions & 2 deletions pages/[name].js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { serverSideTranslations } from 'next-i18next/serverSideTranslations';

import cfg from '../data/config.js';
import { i18n } from '../next-i18next.config.js';
import { findPost, getPostsList, getPostAwailableLocales } from '../api/index.js';
import { findPost, getPublishedPosts, getPostAwailableLocales } from '../api/index.js';
import DefaultLayout from '../components/DefaultLayout.jsx';
import PostPageInfo from '../components/PostPageInfo.jsx';
import MicrometricArticles from '../components/MicrometricArticles.jsx';
Expand Down Expand Up @@ -70,7 +70,7 @@ export const getStaticProps = async ({ locales, locale, params, defaultLocale })

export const getStaticPaths = async () => {
const promises = i18n.locales.map(async (locale) => {
const posts = await getPostsList(locale);
const posts = await getPublishedPosts(locale);

return posts
.filter(({ redirect_to }) => !redirect_to)
Expand Down
4 changes: 2 additions & 2 deletions pages/amp/[name].js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';

import { i18n } from '../../next-i18next.config.js';
import { findPost, getPostAwailableLocales, getPostsList } from '../../api/index.js';
import { findPost, getPublishedPosts, getPostAwailableLocales } from '../../api/index.js';
import AmpLayout from '../../components/AmpLayout.jsx';
import AmpPostPageInfo from '../../components/AmpPostPageInfo.jsx';
import MicrometricArticles from '../../components/MicrometricArticles.jsx';
Expand Down Expand Up @@ -56,7 +56,7 @@ export const getStaticProps = async ({ locale, params, locales, defaultLocale })

export const getStaticPaths = async () => {
const promises = i18n.locales.map(async (locale) => {
const posts = await getPostsList(locale);
const posts = await getPublishedPosts(locale);

return posts
.filter(({ redirect_to }) => !redirect_to)
Expand Down

0 comments on commit 22a6866

Please sign in to comment.