Skip to content

Commit

Permalink
✨ Support for draft files
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Nov 4, 2019
1 parent 43c6045 commit 48a1e0d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions content/getting-started/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
emoji: 🛠️
draft: true
---

# Getting started
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@staart/site",
"version": "1.5.5",
"version": "1.5.6",
"module": "dist/module.js",
"main": "dist/index.js",
"bin": "./dist/index.js",
Expand Down
21 changes: 17 additions & 4 deletions src/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { join, parse } from "path";
import { getConfig } from "./config";
import recursiveReadDir from "recursive-readdir";
import { cached } from "./cache";
import { FrontMatter } from "./interfaces";
import frontMatter from "front-matter";

export const getContentPath = async () => {
const config = await getConfig();
Expand Down Expand Up @@ -73,8 +75,10 @@ export const listRootFiles = async () => {
);
const result = [];
for await (const file of files) {
if (await safeReadFile(join(await getContentPath(), file)))
result.push(file);
const content =
(await safeReadFile(join(await getContentPath(), file))) || "";
const attributes = frontMatter<FrontMatter>(content).attributes;
if (content && !attributes.draft) result.push(file);
}
return result;
};
Expand Down Expand Up @@ -104,7 +108,16 @@ export const listContentFiles = async (
.map(ext => `.${ext}`)
.includes(parse(name).ext)
);
let finalFiles: string[] = [];
for await (const file of files) {
const content =
(await safeReadFile(join(await getContentPath(), file))) || "";
const attributes = frontMatter<FrontMatter>(content).attributes;
if (content && !attributes.draft) {
finalFiles.push(file);
}
}
if (removeContentPath)
files = files.map(file => file.replace(`${contentPath}/`, ""));
return files;
finalFiles = finalFiles.map(file => file.replace(`${contentPath}/`, ""));
return finalFiles;
};
3 changes: 2 additions & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ export interface FrontMatter {
emoji: string;
seoImage: string;
description: string;
[index: string]: string;
draft: boolean;
[index: string]: string | boolean;
}

0 comments on commit 48a1e0d

Please sign in to comment.