Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 38 additions & 14 deletions src/models/Feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ export default class Feed {
if (!post.valid) {
throw Logger.error("Post is not valid");
}
if (post.skip) {
throw Logger.error("Post is marked to be skipped");
}
if (post.status !== PostStatus.UNSCHEDULED) {
throw Logger.error("Post is not unscheduled");
}
Expand Down Expand Up @@ -350,6 +353,9 @@ export default class Feed {
if (!post.valid) {
throw Logger.error("Post is not valid");
}
if (post.skip) {
throw Logger.error("Post is marked to be skipped");
}
if (post.status !== PostStatus.UNSCHEDULED) {
throw Logger.error("Post is not unscheduled");
}
Expand All @@ -363,7 +369,7 @@ export default class Feed {
/**
* Publish single post
*
* Will publish the post regardless of its status
* Will publish the post regardless of its status or skip
* @param path - path to a single folder
* @param platformId - the platform for the post
* @param dryrun - wether or not to really publish
Expand All @@ -380,13 +386,13 @@ export default class Feed {
const platform = this.getPlatform(platformId);
const folder = this.getFolder(path);
const post = platform.getPost(folder);
if (post.valid) {
if (!dryrun) post.schedule(now);
Logger.info("Posting", platformId, path);
await platform.publishPost(post, dryrun);
} else {
if (!post.valid) {
throw Logger.error("Post is not valid");
}
if (!dryrun) post.schedule(now);
Logger.info("Posting", platformId, path);
await platform.publishPost(post, dryrun);

return post;
}

Expand Down Expand Up @@ -416,12 +422,16 @@ export default class Feed {
for (const folder of folders) {
const post = platform.getPost(folder);
if (post.valid) {
post.schedule(now);
Logger.trace("Posting", platform.id, folder.id);
await platform.publishPost(post, dryrun);
posts.push(post);
if (!post.skip) {
post.schedule(now);
Logger.trace("Posting", post.id);
await platform.publishPost(post, dryrun);
posts.push(post);
} else {
Logger.warn("Skipping post marked skip", post.id);
}
} else {
Logger.warn("Skipping invalid post", platform.id, folder.id);
Logger.warn("Skipping invalid post", post.id);
}
}
}
Expand Down Expand Up @@ -500,7 +510,12 @@ export default class Feed {
const nextDate = date ? date : this.getNextPostDate(platform.id);
for (const folder of folders) {
const post = platform.getPost(folder);
if (post.valid && post?.status === PostStatus.UNSCHEDULED) {
if (
post &&
post.valid &&
!post.skip &&
post.status === PostStatus.UNSCHEDULED
) {
post.schedule(nextDate);
posts.push(post);
break;
Expand Down Expand Up @@ -537,9 +552,18 @@ export default class Feed {
for (const platform of platforms) {
for (const folder of folders) {
const post = platform.getPost(folder);
if (post?.status === PostStatus.SCHEDULED) {
if (post && post.status === PostStatus.SCHEDULED) {
if (post.skip) {
Logger.warn(
"Not publishing scheduled post marked skip. Unscheduling post.",
post.id,
);
post.status = PostStatus.UNSCHEDULED;
post.save();
continue;
}
if (post.scheduled <= now) {
console.log("Posting", platform.id, folder.id);
console.log("Posting", post.id);
await platform.publishPost(post, dryrun);
posts.push(post);
break;
Expand Down
1 change: 1 addition & 0 deletions src/models/Folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export default class Folder {

export interface FileInfo {
name: string;
original?: string;
basename: string;
extension: string;
group: string;
Expand Down
40 changes: 35 additions & 5 deletions src/models/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ export default class Platform {
*
* Do not throw errors. Instead, catch and log them,
* and set the post.valid to false
*
* Presume the post may have already been prepared
* before, and manually adapted later. For example,
* post.skip may have manually been set to true.
* @param folder - the folder for which to prepare a post for this platform
* @returns the prepared post
*/
Expand All @@ -137,9 +141,23 @@ export default class Platform {
}

// some default logic. override this
// in your own platform if you need.
// in your own platform if you want;
// but more likely, call super.preparePost
// before adding your own logic.

// always update the files, they may have changed
// on disk; but also maintain some properties that may have
// been changed manually

post.purgeFiles();
const files = await folder.getFiles();
files.forEach((file) => {
if (!post.ignoreFiles.includes(file.name)) {
post.putFile(file);
}
});
post.reorderFiles();

post.files = await folder.getFiles();
const textFiles = post.getFiles("text");

if (post.hasFile("body.txt")) {
Expand All @@ -153,13 +171,25 @@ export default class Platform {

if (post.hasFile("title.txt")) {
post.title = fs.readFileSync(post.folder.path + "/title.txt", "utf8");
} else {
post.title = post.body.split("\n", 1)[0];
} else if (post.hasFile("subject.txt")) {
post.title = fs.readFileSync(post.folder.path + "/subject.txt", "utf8");
}

if (post.hasFile("tags.txt")) {
post.tags = fs.readFileSync(post.folder.path + "/tags.txt", "utf8");
post.tags = fs
.readFileSync(post.folder.path + "/tags.txt", "utf8")
.split(/\s/);
}
if (post.hasFile("mentions.txt")) {
post.mentions = fs
.readFileSync(post.folder.path + "/mentions.txt", "utf8")
.split(/\s/);
}
if (post.hasFile("geo.txt")) {
post.geo = fs.readFileSync(post.folder.path + "/geo.txt", "utf8");
}

post.decompileBody();

if (post.title) {
post.valid = true;
Expand Down
Loading