Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
techxplorer committed Sep 14, 2024
2 parents d56c41b + de93828 commit a5ba7e3
Show file tree
Hide file tree
Showing 14 changed files with 1,981 additions and 47 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ The app has the following options:

| Short option | Long option | Description |
| ------------ | ----------- | ----------- |
| -f | --force | Overwrite files in the status or content archive |
| -d | --debug | Output environment variable content |
| -f | --force | Overwrite files in the status or content archive |
| -t | --tag <tag> | Only add new statuses with the matching tag |

## Configuration ##

Expand Down Expand Up @@ -72,8 +73,7 @@ contains an index.md file and the attached media.

The following items are on my road map:

1. Filter the creation of content by tag
2. Add any other functionality as required
1. Add any other functionality as required

## Rationale ##

Expand Down
15 changes: 12 additions & 3 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ async function run() {
.description( appPackage.getDescription() )
.showHelpAfterError( "(add --help for additional information)" )
.option( "-f, --force", "overwrite existing files" )
.option( "-d, --debug", "output debug information")
.option( "-d, --debug", "output debug information" )
.option( "-t, --tag <tag>", "include only statuses with this tag")
.addHelpText(
"after",
`\nMore info: ${ appPackage.getHomepage() }\nVersion: ${ appPackage.getVersion() }`
Expand Down Expand Up @@ -68,7 +69,11 @@ async function run() {
.description( "update content using archived statuses" )
.action( async() => {
const options = program.opts();
const updateContent = new UpdateContent( options.force, options.debug );
const updateContent = new UpdateContent(
options.force,
options.debug,
options.tag
);
await updateContent.run();
} );

Expand All @@ -77,7 +82,11 @@ async function run() {
.description( "update photos using archived statuses" )
.action( async() => {
const options = program.opts();
const updateContent = new UpdatePhotos( options.force, options.debug );
const updateContent = new UpdatePhotos(
options.force,
options.debug,
options.tag
);
await updateContent.run();
} );

Expand Down
44 changes: 22 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "intrepid-toot-archiver",
"version": "1.2.0",
"version": "1.3.0",
"description": "A CLI app to make an archive of toots",
"main": "index.js",
"bin": {
Expand Down Expand Up @@ -43,7 +43,7 @@
"eslint-plugin-jsdoc": "^50.0.0",
"globals": "^15.8.0",
"jsdoc": "~4.0.3",
"nock": "^14.0.0-beta.11",
"nock": "^14.0.0-beta.13",
"rimraf": "^6.0.1"
}
}
14 changes: 11 additions & 3 deletions src/commands/update-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ class UpdateContent {

allowOverwrite = false;
debugOutput = false;
statusTagFilter = false;

/**
* Update the content archive.
* @param {boolean} force Overwrite any existing content in the archive.
* @param {boolean} debug Output configuration variables.
* @param {string|false} statusTagFilter Only add statuses with this tag.
*/
constructor( force = false, debug = false ) {
constructor( force = false, debug = false, statusTagFilter = false ) {

if ( force ) {
this.allowOverwrite = true;
Expand All @@ -30,6 +32,10 @@ class UpdateContent {
this.debugOutput = true;
}

if ( statusTagFilter !== false ) {
this.statusTagFilter = statusTagFilter;
}

}

/**
Expand All @@ -53,7 +59,8 @@ class UpdateContent {
if ( this. debugOutput ) {
console.log( chalk.bold.underline( "\nEnvironment variables" ) );
console.log( "Status archive path: %s", process.env.ITA_ARCHIVE_PATH );
console.log( "Content archive path: %s%s", process.env.ITA_ARCHIVE_PATH, "\n" );
console.log( "Content archive path: %s", process.env.ITA_ARCHIVE_PATH );
console.log( "Tag used to filter posts: %s%s", this.statusTagFilter, "\n" );
}

const statusArchive = new StatusArchive(
Expand All @@ -62,7 +69,8 @@ class UpdateContent {

const contentArchive = new ContentArchive(
contentArchivePath,
this.allowOverwrite
this.allowOverwrite,
this.statusTagFilter
);

if ( this.allowOverwrite ) {
Expand Down
18 changes: 13 additions & 5 deletions src/commands/update-photos.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ class UpdatePhotos {

allowOverwrite = false;
debugOutput = false;
statusTagFilter = false;

/**
* Update the content archive.
* Update the photo archive.
* @param {boolean} force Overwrite any existing content in the archive.
* @param {boolean} debug Output configuration variables.
* @param {string|false} statusTagFilter Only add statuses with this tag.
*/
constructor( force = false, debug = false ) {
constructor( force = false, debug = false, statusTagFilter = false ) {

if ( force ) {
this.allowOverwrite = true;
Expand All @@ -30,6 +32,10 @@ class UpdatePhotos {
this.debugOutput = true;
}

if ( statusTagFilter !== false ) {
this.statusTagFilter = statusTagFilter;
}

}

/**
Expand Down Expand Up @@ -59,8 +65,9 @@ class UpdatePhotos {
if ( this. debugOutput ) {
console.log( chalk.bold.underline( "\nEnvironment variables" ) );
console.log( "Status archive path: %s", process.env.ITA_ARCHIVE_PATH );
console.log( "Content archive path: %s%s", process.env.ITA_ARCHIVE_PATH, "\n" );
console.log( "Media archive path: %s%s", process.env.ITA_ARCHIVE_PATH, "\n" );
console.log( "Content archive path: %s", process.env.ITA_ARCHIVE_PATH );
console.log( "Media archive path: %s", process.env.ITA_ARCHIVE_PATH );
console.log( "Tag used to filter posts: %s%s", this.statusTagFilter, "\n" );
}

const statusArchive = new StatusArchive(
Expand All @@ -74,7 +81,8 @@ class UpdatePhotos {

const photoArchive = new PhotoArchive(
contentArchivePath,
this.allowOverwrite
this.allowOverwrite,
this.statusTagFilter
);

const statusCount = await statusArchive.loadContents();
Expand Down
46 changes: 45 additions & 1 deletion src/lib/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,20 @@ class Archive {
*/
fileExtension = undefined;

/**
* The tag used to filter the list of statuses.
* @type {string}
*/
statusFilter = false;

/**
* Manage the archive of contents.
* @param {string} archivePath The path to the content archive directory.
* @param {boolean} overwriteFlag Flag indicating if files should be overwritten.
* @param {string} statusFilter An optional tag used to filter the list of statuses.
* @throws {TypeError} When the parameters are incorrect.
*/
constructor( archivePath, overwriteFlag = false ) {
constructor( archivePath, overwriteFlag = false, statusFilter = false ) {

let syncStatus = null;

Expand All @@ -73,6 +80,8 @@ class Archive {
};
}

this.statusFilter = statusFilter;

}

/**
Expand Down Expand Up @@ -153,6 +162,41 @@ class Archive {
return this.contents;
}

/**
* Check to see if a status has a tag.
* @param {object} status An object representing a status.
* @param {string} tag The tag that the status must have.
* @returns {boolean} True, if the status has the tag, otherwise false.
* @throws {TypeError} When the parameters are incorrect.
*/
statusHasTag( status, tag ) {

if ( typeof status !== "object" ) {
throw new TypeError( "The status parameter must be an object" );
}

if ( typeof tag !== "string" ) {
throw new TypeError( "The tag parameter must be a string" );
}

if ( status.tags === undefined ) {
throw new TypeError( "The status is expected to have a 'tags' property" );
}

if ( !Array.isArray( status.tags ) ) {
throw new TypeError( "The tags property is expected to be an array" );
}

for ( const statusTag of status.tags ) {
if ( statusTag.name === tag ) {
return true;
}
}

return false;

}

}

export default Archive;
11 changes: 9 additions & 2 deletions src/lib/content-archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ class ContentArchive extends Archive {
* Manage the Content Archive.
* @param {string} archivePath The path to the content archive directory.
* @param {boolean} overwriteFlag Flag indicating if files should be overwritten.
* @param {string} statusFilter An optional tag used to filter the list of statuses.
* @throws {TypeError} When the parameters are incorrect.
*/
constructor( archivePath, overwriteFlag = false ) {
super( archivePath, overwriteFlag );
constructor( archivePath, overwriteFlag = false, statusFilter = false ) {
super( archivePath, overwriteFlag, statusFilter );
this.fileExtension = ".md";
this.contentCreator = new ContentCreator();
}
Expand Down Expand Up @@ -75,6 +76,12 @@ class ContentArchive extends Archive {
statusContent.toString()
);

if ( this.statusFilter !== false ) {
if ( this.statusHasTag( status, this.statusFilter ) === false ) {
continue;
}
}

const newContent = [];
newContent.push( "---" );
newContent.push( this.contentCreator.createFrontMatter( status ) );
Expand Down
Loading

0 comments on commit a5ba7e3

Please sign in to comment.