diff --git a/CMakeLists.txt b/CMakeLists.txt index f1e691d..32a69c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.2) project(remwharead - VERSION 0.3.2 + VERSION 0.4.0 LANGUAGES CXX ) diff --git a/remwharead.1.adoc b/remwharead.1.adoc index b6b477a..bd1ae79 100644 --- a/remwharead.1.adoc +++ b/remwharead.1.adoc @@ -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_ diff --git a/src/bookmarks.cpp b/src/bookmarks.cpp new file mode 100644 index 0000000..505d272 --- /dev/null +++ b/src/bookmarks.cpp @@ -0,0 +1,52 @@ +/* This file is part of remwharead. + * Copyright © 2019 tastytea + * + * 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 . + */ + +#include +#include "export.hpp" + +using std::chrono::system_clock; +using std::chrono::duration_cast; +using std::chrono::seconds; + +void export_bookmarks(const vector &entries, ostream &out) +{ + out << "\n" + "\n" + "Bookmarks from remwharead\n" + "

Bookmarks from remwharead

\n\n" + "

\n" + "

remwharead

\n" + "

\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(duration).count()); + + out << "

" + << title << "\n"; + } + out << "

\n" + << "

\n"; +} diff --git a/src/export.hpp b/src/export.hpp index 22b795c..3f95a5e 100644 --- a/src/export.hpp +++ b/src/export.hpp @@ -33,4 +33,8 @@ void export_adoc(const vector &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 &entries, + ostream &out = cout); #endif // REMWHAREAD_EXPORT_HPP diff --git a/src/main.cpp b/src/main.cpp index a611c4a..02cbf77 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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; diff --git a/src/parse_options.cpp b/src/parse_options.cpp index 66005ea..26fcb1f 100644 --- a/src/parse_options.cpp +++ b/src/parse_options.cpp @@ -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); } } diff --git a/src/types.hpp b/src/types.hpp index 7c3203e..be23767 100644 --- a/src/types.hpp +++ b/src/types.hpp @@ -21,7 +21,8 @@ enum class export_format { undefined, csv, - asciidoc + asciidoc, + bookmarks }; #endif // REMWHAREAD_TYPES_HPP