Skip to content

Commit

Permalink
Add options to keep title and excerpt when update
Browse files Browse the repository at this point in the history
  • Loading branch information
RadhiFadlillah committed Aug 10, 2019
1 parent 7dbb63d commit 11c6680
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 24 deletions.
6 changes: 3 additions & 3 deletions internal/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func updateCmd() *cobra.Command {
cmd.Flags().StringSliceP("tags", "t", []string{}, "Comma-separated tags for this bookmark")
cmd.Flags().BoolP("offline", "o", false, "Update bookmark without fetching data from internet")
cmd.Flags().BoolP("yes", "y", false, "Skip confirmation prompt and update ALL bookmarks")
cmd.Flags().Bool("dont-overwrite", false, "Don't overwrite existing metadata. Useful when only want to update bookmark's content")
cmd.Flags().Bool("keep-metadata", false, "Keep existing metadata. Useful when only want to update bookmark's content")
cmd.Flags().BoolP("no-archival", "a", false, "Update bookmark without updating offline archive")
cmd.Flags().Bool("log-archival", false, "Log the archival process")

Expand All @@ -57,7 +57,7 @@ func updateHandler(cmd *cobra.Command, args []string) {
skipConfirm, _ := cmd.Flags().GetBool("yes")
noArchival, _ := cmd.Flags().GetBool("no-archival")
logArchival, _ := cmd.Flags().GetBool("log-archival")
dontOverwrite := cmd.Flags().Changed("dont-overwrite")
keepMetadata := cmd.Flags().Changed("keep-metadata")

// If no arguments (i.e all bookmarks going to be updated), confirm to user
if len(args) == 0 && !skipConfirm {
Expand Down Expand Up @@ -215,7 +215,7 @@ func updateHandler(cmd *cobra.Command, args []string) {
book.Content = ""
}

if !dontOverwrite {
if !keepMetadata {
book.Title = article.Title
book.Excerpt = article.Excerpt
}
Expand Down
2 changes: 2 additions & 0 deletions internal/view/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,15 @@
showId = (typeof opts.showId === "boolean") ? opts.showId : false,
listMode = (typeof opts.listMode === "boolean") ? opts.listMode : false,
nightMode = (typeof opts.nightMode === "boolean") ? opts.nightMode : false,
keepMetadata = (typeof opts.keepMetadata === "boolean") ? opts.keepMetadata : false,
useArchive = (typeof opts.useArchive === "boolean") ? opts.useArchive : false,
makePublic = (typeof opts.makePublic === "boolean") ? opts.makePublic : false;

this.displayOptions = {
showId: showId,
listMode: listMode,
nightMode: nightMode,
keepMetadata: keepMetadata,
useArchive: useArchive,
makePublic: makePublic,
};
Expand Down
2 changes: 2 additions & 0 deletions internal/view/js/page/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export default {
showId: false,
listMode: false,
nightMode: false,

keepMetadata: false,
useArchive: false,
makePublic: false,
};
Expand Down
6 changes: 6 additions & 0 deletions internal/view/js/page/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,11 @@ export default {
title: "Update Cache",
content: "Update cache for selected bookmarks ? This action is irreversible.",
fields: [{
name: "keepMetadata",
label: "Keep the old title and excerpt",
type: "check",
value: this.displayOptions.keepMetadata,
}, {
name: "createArchive",
label: "Update archive as well",
type: "check",
Expand All @@ -568,6 +573,7 @@ export default {
var data = {
ids: ids,
createArchive: data.createArchive,
keepMetadata: data.keepMetadata,
};

this.dialog.loading = true;
Expand Down
5 changes: 5 additions & 0 deletions internal/view/js/page/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ var template = `
</details>
<details open class="setting-group" id="setting-bookmarks">
<summary>Bookmarks</summary>
<label>
<input type="checkbox" v-model="displayOptions.keepMetadata" @change="saveSetting">
Keep bookmark's metadata when updating
</label>
<label>
<input type="checkbox" v-model="displayOptions.useArchive" @change="saveSetting">
Create archive by default
Expand Down Expand Up @@ -77,6 +81,7 @@ export default {
showId: this.displayOptions.showId,
listMode: this.displayOptions.listMode,
nightMode: this.displayOptions.nightMode,
keepMetadata: this.displayOptions.keepMetadata,
useArchive: this.displayOptions.useArchive,
makePublic: this.displayOptions.makePublic,
});
Expand Down
24 changes: 12 additions & 12 deletions internal/webserver/assets-prod.go

Large diffs are not rendered by default.

16 changes: 7 additions & 9 deletions internal/webserver/handler-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ func (h *handler) apiUpdateCache(w http.ResponseWriter, r *http.Request, ps http
// Decode request
request := struct {
IDs []int `json:"ids"`
KeepMetadata bool `json:"keepMetadata"`
CreateArchive bool `json:"createArchive"`
}{}

Expand Down Expand Up @@ -494,7 +495,7 @@ func (h *handler) apiUpdateCache(w http.ResponseWriter, r *http.Request, ps http
for i, book := range bookmarks {
wg.Add(1)

go func(i int, book model.Bookmark) {
go func(i int, book model.Bookmark, keepMetadata bool) {
// Make sure to finish the WG
defer wg.Done()

Expand Down Expand Up @@ -549,18 +550,15 @@ func (h *handler) apiUpdateCache(w http.ResponseWriter, r *http.Request, ps http
book.Content = article.TextContent
book.HTML = article.Content

if article.Title != "" {
book.Title = article.Title
if !isReadable {
book.Content = ""
}

if article.Excerpt != "" {
if !keepMetadata {
book.Title = article.Title
book.Excerpt = article.Excerpt
}

if !isReadable {
book.Content = ""
}

book.HasContent = book.Content != ""

// Get image for thumbnail and save it to local disk
Expand Down Expand Up @@ -609,7 +607,7 @@ func (h *handler) apiUpdateCache(w http.ResponseWriter, r *http.Request, ps http
mx.Lock()
bookmarks[i] = book
mx.Unlock()
}(i, book)
}(i, book, request.KeepMetadata)
}

// Receive all problematic bookmarks
Expand Down

0 comments on commit 11c6680

Please sign in to comment.