Make hashtag-replacement optional.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
tastytea 2020-10-29 15:06:51 +01:00
parent 0e61a876bc
commit 2554779759
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
4 changed files with 21 additions and 5 deletions

View File

@ -2,7 +2,7 @@
:doctype: manpage
:Author: tastytea
:Email: tastytea@tastytea.de
:Date: 2020-05-10
:Date: 2020-10-29
:Revision: 0.0.0
:man source: mastorss
:man manual: General Commands Manual
@ -32,8 +32,9 @@ Show version, copyright and license.
Put `watchwords.json` into `${XDG_CONFIG_HOME}/mastorss/`. Launch with profile
name. The first occurence of every watchword in an RSS item will be turned into
a hashtag. For profile-specific watchwords see the example in
`watchwords.json`. In the first run only the newest entry is posted.
a hashtag (unless *add_hashtags* is set to false). For profile-specific
watchwords see the example in `watchwords.json`. In the first run only the
newest entry is posted unless *keep_looking* is set to true.
The profile is the identifier for a feed and can't be named "global".
@ -95,6 +96,9 @@ Object with a list of regular expressions and replacements. Applies to posts,
subjects and links, but not to the string in _append_. For information about the
syntax see *perlre*(1).
*add_hashtags*::
If true, replace words with hashtags according to `watchwords.json`.
== EXAMPLES
=== Configuration file

View File

@ -91,7 +91,8 @@ std::ostream &operator<<(std::ostream &out, const ProfileData &data)
out << ", ";
}
}
out << "]";
out << "], ";
out << "add_hashtags: " << data.add_hashtags;
return out;
}
@ -194,6 +195,10 @@ void Config::generate()
}
profiledata.max_size = stoul(line);
cout << "Add hashtags according to watchwords.json? [y/n]: ";
std::getline(cin, line);
profiledata.add_hashtags = (line[0] == 'y');
BOOST_LOG_TRIVIAL(debug) << "Generated configuration.";
write();
}
@ -254,6 +259,7 @@ void Config::parse()
profiledata.replacements.push_back(
{search, _json[profile]["replacements"][search].asString()});
}
profiledata.add_hashtags = _json[profile]["add_hashtags"].asBool();
BOOST_LOG_TRIVIAL(debug) << "Read config: " << profiledata;
}
@ -277,6 +283,7 @@ void Config::write()
{
_json[profile]["replacements"][replacement.first] = replacement.second;
}
_json[profile]["add_hashtags"] = profiledata.add_hashtags;
ofstream file{get_filename().c_str()};
if (file.good())

View File

@ -55,6 +55,7 @@ struct ProfileData
bool titles_as_cw{false};
bool titles_only{false};
list<pair<string, string>> replacements;
bool add_hashtags{true};
friend std::ostream &operator<<(std::ostream &out, const ProfileData &data);
};

View File

@ -213,7 +213,11 @@ void Document::parse_rss(const pt::ptree &tree)
desc = regex_replace(desc, regex{fix}, "");
}
desc = remove_html(desc);
return add_hashtags(desc);
if (_profiledata.add_hashtags)
{
desc = add_hashtags(desc);
}
return desc;
}();
// clang-format on
item.guid = move(guid);