Add export: link.

A plain list of links, separated by newline. Closes #2.
This commit is contained in:
tastytea 2019-11-27 21:53:48 +01:00
parent e1ad1a3588
commit 45668b6c9f
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
6 changed files with 98 additions and 4 deletions

39
include/export/link.hpp Normal file
View File

@ -0,0 +1,39 @@
/* This file is part of remwharead.
* Copyright © 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef REMWHAREAD_EXPORT_LINK_HPP
#define REMWHAREAD_EXPORT_LINK_HPP
#include "export.hpp"
namespace remwharead::Export
{
/*!
* @brief Export as list of hyperlinks.
*
* @since 0.9.0
*
* @headerfile link.hpp remwharead/export/link.hpp
*/
class Link : protected ExportBase
{
public:
using ExportBase::ExportBase;
void print() const override;
};
} // namespace remwharead::Export
#endif // REMWHAREAD_EXPORT_LINK_HPP

View File

@ -36,7 +36,8 @@ enum class export_format
bookmarks,
simple,
json,
rss
rss,
link
};
} // namespace remwharead

View File

@ -2,7 +2,7 @@
:doctype: manpage
:Author: tastytea
:Email: tastytea@tastytea.de
:Date: 2019-10-15
:Date: 2019-11-27
:Revision: 0.0.0
:man source: remwharead
:man manual: General Commands Manual
@ -24,7 +24,7 @@ remwharead - Saves URIs of things you want to remember in a database
the full text of the page and optional tags.
The database can be filtered by time, tags and full text and exported to CSV,
AsciiDoc, a bookmarks file, JSON or RSS.
AsciiDoc, a bookmarks file, JSON, RSS or a list of hyperlinks.
Archiving is done using the Wayback machine from the
https://archive.org/[Internet Archive].
@ -36,7 +36,7 @@ Add tags to _URI_, delimited by commas.
*-e*=_format_, *--export*=_format_::
Export to _format_. Possible values are _csv_, _asciidoc_, _bookmarks_,
_simple_, _json_ or _rss_. See _FORMATS_.
_simple_, _json_, _rss_ or _link_. See _FORMATS_.
*-f*=_file_, *--file*=_file_::
Save output to _file_. Default is stdout.
@ -149,6 +149,10 @@ Export as http://www.rssboard.org/rss-specification[RSS] feed. Because the URL
of the feed is unknown to *remwharead*, the generated feed is slightly out of
specification (the element _link_ in _channel_ is empty).
=== link
Export as a plain list of links, separated by newlines.
== SEARCH EXPRESSIONS
A search expression is either a single term, or several terms separated by _AND_

View File

@ -19,6 +19,7 @@
#include "export/bookmarks.hpp"
#include "export/csv.hpp"
#include "export/json.hpp"
#include "export/link.hpp"
#include "export/rss.hpp"
#include "export/simple.hpp"
#include "search.hpp"
@ -214,6 +215,19 @@ int App::main(const std::vector<std::string> &args)
}
break;
}
case export_format::link:
{
if (file.is_open())
{
Export::Link(entries, file).print();
file.close();
}
else
{
Export::Link(entries).print();
}
break;
}
default:
{
break;

View File

@ -146,6 +146,10 @@ void App::handle_options(const std::string &name, const std::string &value)
{
_format = export_format::rss;
}
else if (value == "link")
{
_format = export_format::link;
}
else
{
cerr << "Error: Unknown format.\n";

32
src/lib/export/link.cpp Normal file
View File

@ -0,0 +1,32 @@
/* This file is part of remwharead.
* Copyright © 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "export/link.hpp"
#include "sqlite.hpp"
#include <string>
namespace remwharead
{
using std::string;
void Export::Link::print() const
{
for (const Database::entry & entry : _entries)
{
_out << entry.uri << '\n';
}
}
} // namespace remwharead