-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1542cab
commit 8d31910
Showing
6 changed files
with
110 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { SyncConfig, config as default_config } from "./config"; | ||
import { sync as command_sync } from "./commands/sync"; | ||
|
||
export async function sync(config: Partial<SyncConfig>) { | ||
await command_sync({ | ||
...default_config, | ||
...config, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Config } from "convict"; | ||
|
||
import { SyncConfig } from "../config"; | ||
import { | ||
rootFolderExists, | ||
getMasterArticlesWithMasterId, | ||
haveDuplicateMasterIDs, | ||
} from "../masterArticles/master-articles"; | ||
import { error } from "console"; | ||
import { syncBlogPlatformsWithMasters } from "../sync/sync"; | ||
|
||
export async function sync(config: SyncConfig) { | ||
/** | ||
* Stop if root folder does not exist | ||
*/ | ||
if (!(await rootFolderExists(config.rootFolder))) { | ||
error(` | ||
Root folder not found: ${config.rootFolder} | ||
Run $ papertown sync --rootFolder yourrootfolder | ||
`); | ||
return; | ||
} | ||
|
||
/** | ||
* Get all articles with an masterid in the frontmatter | ||
*/ | ||
const masterArticles = await getMasterArticlesWithMasterId( | ||
config.rootFolder, | ||
config.imageRootUrlGithub | ||
); | ||
|
||
/** | ||
* Stop if no master articles were found | ||
*/ | ||
if (masterArticles.length === 0) { | ||
error(` | ||
No articles found with masterid. | ||
Add a masterid to the frontmatter of post | ||
you want to sync | ||
`); | ||
return; | ||
} | ||
|
||
/** | ||
* Stop if a masterid is used twice | ||
*/ | ||
if (haveDuplicateMasterIDs(masterArticles)) { | ||
error("Articles have duplicate master ids"); | ||
return; | ||
} | ||
|
||
/** | ||
* Sync all master articles | ||
*/ | ||
await syncBlogPlatformsWithMasters(masterArticles, config); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters