diff options
author | vnugent <public@vaughnnugent.com> | 2024-02-02 17:04:47 -0500 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2024-02-02 17:04:47 -0500 |
commit | dd5e5164262c5ff7ecf6db1003d41d81e6364c09 (patch) | |
tree | 9b5a34f0c57eeb55f7625f2eb60b191a494d1758 /back-end/src/ImportExportUtil.cs | |
parent | dab4c63543af688e67661b0091b49edb00e9557d (diff) |
add bookmark export, fix some ui stuff
Diffstat (limited to 'back-end/src/ImportExportUtil.cs')
-rw-r--r-- | back-end/src/ImportExportUtil.cs | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/back-end/src/ImportExportUtil.cs b/back-end/src/ImportExportUtil.cs new file mode 100644 index 0000000..3610ef6 --- /dev/null +++ b/back-end/src/ImportExportUtil.cs @@ -0,0 +1,77 @@ +// Copyright (C) 2024 Vaughn Nugent +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +using System; +using System.IO; +using SimpleBookmark.Model; +using System.Collections.Generic; +using VNLib.Utils.IO; + + + +namespace SimpleBookmark +{ + internal static class ImportExportUtil + { + /// <summary> + /// Exports a colletion of bookmarks to a netscape bookmark file + /// </summary> + /// <param name="bookmarks">The bookmark collection to export</param> + /// <param name="outputStream">The bookmark output stream to write data to</param> + public static void ExportToNetscapeFile(IEnumerable<BookmarkEntry> bookmarks, Stream outputStream) + { + using VnStreamWriter writer = new(outputStream, System.Text.Encoding.UTF8, 1024) + { + NewLine = "\r\n" + }; + + writer.WriteLine("<!DOCTYPE NETSCAPE-Bookmark-file-1>"); + writer.WriteLine("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">"); + writer.WriteLine("<TITLE>Bookmarks</TITLE>"); + writer.WriteLine("<H1>Bookmarks</H1>"); + writer.WriteLine("<DL><p>"); + + //Add each bookmark + foreach (BookmarkEntry entry in bookmarks) + { + writer.Write("<DT><A HREF=\""); + writer.Write(entry.Url); + + writer.Write("\" ADD_DATE=\""); + writer.Write(new DateTimeOffset(entry.Created).ToUnixTimeSeconds()); + + writer.Write("\" LAST_VISIT=\""); + writer.Write(new DateTimeOffset(entry.LastModified).ToUnixTimeSeconds()); + + //tags + writer.Write("\" TAGS=\""); + writer.Write(entry.Tags); + + writer.Write("\">"); + writer.Write(entry.Name); + writer.WriteLine("</A>"); + + //description + writer.Write("<DD>"); + writer.WriteLine(entry.Description); + + } + + //Close document + writer.WriteLine("</DL></p>"); + writer.Flush(); + } + } +} |