Make hashtag-replacement optional.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0e61a876bc
commit
2554779759
|
@ -2,7 +2,7 @@
|
||||||
:doctype: manpage
|
:doctype: manpage
|
||||||
:Author: tastytea
|
:Author: tastytea
|
||||||
:Email: tastytea@tastytea.de
|
:Email: tastytea@tastytea.de
|
||||||
:Date: 2020-05-10
|
:Date: 2020-10-29
|
||||||
:Revision: 0.0.0
|
:Revision: 0.0.0
|
||||||
:man source: mastorss
|
:man source: mastorss
|
||||||
:man manual: General Commands Manual
|
: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
|
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
|
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
|
a hashtag (unless *add_hashtags* is set to false). For profile-specific
|
||||||
`watchwords.json`. In the first run only the newest entry is posted.
|
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".
|
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
|
subjects and links, but not to the string in _append_. For information about the
|
||||||
syntax see *perlre*(1).
|
syntax see *perlre*(1).
|
||||||
|
|
||||||
|
*add_hashtags*::
|
||||||
|
If true, replace words with hashtags according to `watchwords.json`.
|
||||||
|
|
||||||
== EXAMPLES
|
== EXAMPLES
|
||||||
|
|
||||||
=== Configuration file
|
=== Configuration file
|
||||||
|
|
|
@ -91,7 +91,8 @@ std::ostream &operator<<(std::ostream &out, const ProfileData &data)
|
||||||
out << ", ";
|
out << ", ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out << "]";
|
out << "], ";
|
||||||
|
out << "add_hashtags: " << data.add_hashtags;
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -194,6 +195,10 @@ void Config::generate()
|
||||||
}
|
}
|
||||||
profiledata.max_size = stoul(line);
|
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.";
|
BOOST_LOG_TRIVIAL(debug) << "Generated configuration.";
|
||||||
write();
|
write();
|
||||||
}
|
}
|
||||||
|
@ -254,6 +259,7 @@ void Config::parse()
|
||||||
profiledata.replacements.push_back(
|
profiledata.replacements.push_back(
|
||||||
{search, _json[profile]["replacements"][search].asString()});
|
{search, _json[profile]["replacements"][search].asString()});
|
||||||
}
|
}
|
||||||
|
profiledata.add_hashtags = _json[profile]["add_hashtags"].asBool();
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(debug) << "Read config: " << profiledata;
|
BOOST_LOG_TRIVIAL(debug) << "Read config: " << profiledata;
|
||||||
}
|
}
|
||||||
|
@ -277,6 +283,7 @@ void Config::write()
|
||||||
{
|
{
|
||||||
_json[profile]["replacements"][replacement.first] = replacement.second;
|
_json[profile]["replacements"][replacement.first] = replacement.second;
|
||||||
}
|
}
|
||||||
|
_json[profile]["add_hashtags"] = profiledata.add_hashtags;
|
||||||
|
|
||||||
ofstream file{get_filename().c_str()};
|
ofstream file{get_filename().c_str()};
|
||||||
if (file.good())
|
if (file.good())
|
||||||
|
|
|
@ -55,6 +55,7 @@ struct ProfileData
|
||||||
bool titles_as_cw{false};
|
bool titles_as_cw{false};
|
||||||
bool titles_only{false};
|
bool titles_only{false};
|
||||||
list<pair<string, string>> replacements;
|
list<pair<string, string>> replacements;
|
||||||
|
bool add_hashtags{true};
|
||||||
|
|
||||||
friend std::ostream &operator<<(std::ostream &out, const ProfileData &data);
|
friend std::ostream &operator<<(std::ostream &out, const ProfileData &data);
|
||||||
};
|
};
|
||||||
|
|
|
@ -213,7 +213,11 @@ void Document::parse_rss(const pt::ptree &tree)
|
||||||
desc = regex_replace(desc, regex{fix}, "");
|
desc = regex_replace(desc, regex{fix}, "");
|
||||||
}
|
}
|
||||||
desc = remove_html(desc);
|
desc = remove_html(desc);
|
||||||
return add_hashtags(desc);
|
if (_profiledata.add_hashtags)
|
||||||
|
{
|
||||||
|
desc = add_hashtags(desc);
|
||||||
|
}
|
||||||
|
return desc;
|
||||||
}();
|
}();
|
||||||
// clang-format on
|
// clang-format on
|
||||||
item.guid = move(guid);
|
item.guid = move(guid);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user