Skip to content

Commit 79c7914

Browse files
committed
Add overwrite option to public preview tool
1 parent 8565ff7 commit 79c7914

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ Insert a public preview divider at a specific point, after the `previewPosition`
344344
# Add a divider to all posts as position 2
345345
gctools add-preview <apiURL> <adminAPIKey> --previewPosition 2
346346

347+
# Add a divider to all posts as position 2, and overwrites if a divider already exists
348+
gctools add-preview <apiURL> <adminAPIKey> --previewPosition 2 --overwrite
349+
347350
# Add a divider to all posts 50% through the post
348351
gctools add-preview <apiURL> <adminAPIKey> --previewPosition 50%
349352

commands/add-preview.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,20 @@ const setup = (sywac) => {
3131
});
3232
sywac.string('--tag', {
3333
defaultValue: null,
34-
desc: 'The tag(s) to be added'
34+
desc: 'Update content with this tag slug'
3535
});
3636
sywac.string('--author', {
3737
defaultValue: null,
38-
desc: 'Delete content with this author slug'
38+
desc: 'Update content with this author slug'
3939
});
4040
sywac.string('-pp --previewPosition', {
4141
defaultValue: '2',
4242
desc: 'The card position index the public preview should be inserted after'
4343
});
44+
sywac.boolean('-o --overwrite', {
45+
defaultValue: false,
46+
desc: 'Overwrite the preview position if one already exists'
47+
});
4448
sywac.number('--delayBetweenCalls', {
4549
defaultValue: 50,
4650
desc: 'The delay between API calls, in ms'

prompts/add-preview.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ const options = [
5959
name: 'previewPosition',
6060
message: 'The card position index the public preview should be inserted after (or percentage, written as "20%"):',
6161
default: '2'
62+
},
63+
{
64+
type: 'confirm',
65+
name: 'overwrite',
66+
message: 'Overwrite the preview position if one already exists?',
67+
default: false
6268
}
6369
];
6470

tasks/add-preview.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,23 @@ const getFullTaskList = (options) => {
102102
return value.type === 'paywall';
103103
});
104104

105+
if (hasPaywallCard) {
106+
if (options.overwrite) {
107+
const paywallCardIndex = updatedLexical.root.children.findIndex((child) => {
108+
return child.type === 'paywall';
109+
});
110+
111+
if (paywallCardIndex > 0) {
112+
// Remove existing paywall card
113+
updatedLexical.root.children.splice(paywallCardIndex, 1);
114+
}
115+
}
116+
}
117+
105118
tasks.push({
106119
title: `${post.title}`,
107120
skip: () => {
108-
if (hasPaywallCard) {
121+
if (hasPaywallCard && options.overwrite === false) {
109122
return `${post.title} (${post.slug}) already has a paywall card`;
110123
}
111124
},

0 commit comments

Comments
 (0)