Added bookmark export.

This commit is contained in:
tastytea 2019-05-26 15:47:06 +02:00
parent 8cd33bb083
commit 747ba749e8
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
7 changed files with 89 additions and 5 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.2)
project(remwharead
VERSION 0.3.2
VERSION 0.4.0
LANGUAGES CXX
)

View File

@ -2,7 +2,7 @@
:doctype: manpage
:Author: tastytea
:Email: tastytea@tastytea.de
:Date: 2019-05-19
:Date: 2019-05-26
:Revision: 0.0.0
:man source: remwharead
:man manual: General Commands Manual
@ -35,7 +35,8 @@ https://archive.org/[Internet Archive].
Add tags to _URI_, delimited by commas.
*-e* _format_, *--export* _format_::
Export to _format_. Possible values are _csv_ and _asciidoc_. See _FORMATS_.
Export to _format_. Possible values are _csv_, _asciidoc_ and _bookmarks_. See
_FORMATS_.
*-f* _file_, *--file* _file_::
Save output to _file_. Default is stdout.
@ -99,6 +100,13 @@ implementation follows RFC 4180 and the full MIME media type is
AsciiDoc is a markup language that can be read as plain text or converted to
HTML, PDF and many other formats.
=== bookmarks
The
https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa753582(v=vs.85)[Netscape
Bookmark file format] is a format for exporting and importing bookmarks that is
understood by most browsers.
== SEARCH EXPRESSIONS
A search expression is either a single term, or several terms separated by _AND_

52
src/bookmarks.cpp Normal file
View File

@ -0,0 +1,52 @@
/* 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 <chrono>
#include "export.hpp"
using std::chrono::system_clock;
using std::chrono::duration_cast;
using std::chrono::seconds;
void export_bookmarks(const vector<Database::entry> &entries, ostream &out)
{
out << "<!DOCTYPE NETSCAPE-Bookmark-file-1>\n"
"<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; "
"charset=UTF-8\">\n"
"<TITLE>Bookmarks from remwharead</TITLE>\n"
"<H1>Bookmarks from remwharead<H1>\n\n"
"<DL><p>\n"
"<DT><H3>remwharead</H3>\n"
"<DL><p>\n";
for (const Database::entry & entry : entries)
{
string title = entry.title;
if (title.empty())
{
title = entry.uri;
}
system_clock::time_point tp = entry.datetime;
system_clock::duration duration = tp.time_since_epoch();
string time_seconds =
std::to_string(duration_cast<seconds>(duration).count());
out << "<DT><A HREF=\"" << entry.uri << "\" "
<< "ADD_DATE=\"" << time_seconds << "\">"
<< title << "</A>\n";
}
out << "</DL><p>\n"
<< "</DL><p>\n";
}

View File

@ -33,4 +33,8 @@ void export_adoc(const vector<Database::entry> &entries, ostream &out = cout);
//! Replaces characters in tags that asciidoctor doesn't like.
const string replace_in_tags(string text);
//! Export as Netscape bookmark file.
void export_bookmarks(const vector<Database::entry> &entries,
ostream &out = cout);
#endif // REMWHAREAD_EXPORT_HPP

View File

@ -23,6 +23,7 @@
#include "sqlite.hpp"
#include "parse_options.hpp"
#include "uri.hpp"
#include "types.hpp"
#include "export.hpp"
#include "search.hpp"
@ -119,6 +120,19 @@ int main(const int argc, const char *argv[])
}
break;
}
case export_format::bookmarks:
{
if (file.is_open())
{
export_bookmarks(entries, file);
file.close();
}
else
{
export_bookmarks(entries);
}
break;
}
default:
{
break;

View File

@ -123,10 +123,15 @@ const options parse_options(const int argc, const char *argv[])
{
opts.format = export_format::asciidoc;
}
else if (format == "bookmarks")
{
opts.format = export_format::bookmarks;
}
else
{
opts.format = export_format::undefined;
cerr << "Error: Export format must be csv or asciidoc.\n";
cerr << "Error: Export format must be "
<< "csv, asciidoc or bookmarks.\n";
return options(1);
}
}

View File

@ -21,7 +21,8 @@ enum class export_format
{
undefined,
csv,
asciidoc
asciidoc,
bookmarks
};
#endif // REMWHAREAD_TYPES_HPP