dotfiles

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 33c88d76d8cd54e75a26c09465804adca4649ff2 (tree)
parent be73f0f6d17fc1b701eef1a3b547eaea78abf22f
Author: Motiejus Jakštys <desired.mta@gmail.com>
Date:   Sun,  7 Jun 2020 16:46:08 +0300

create note/note.go

Diffstat:
Asrc/joplin2site/internal/note/note.go | 91+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/joplin2site/internal/note/parse_test.go -> src/joplin2site/internal/note/note_test.go | 0
Dsrc/joplin2site/internal/note/parse.go | 31-------------------------------
Dsrc/joplin2site/internal/note/types.go | 61-------------------------------------------------------------
4 files changed, 91 insertions(+), 92 deletions(-)

diff --git a/src/joplin2site/internal/note/note.go b/src/joplin2site/internal/note/note.go @@ -0,0 +1,91 @@ +package note + +import ( + "strings" + + "time" + + "gopkg.in/yaml.v2" +) + +// Note is how Joplin understands the note. +type Note struct { + ID string `yaml:"id"` + ParentID string `yaml:"parent_id"` + Title string `yaml:"-"` + Body string `yaml:"-"` + CreatedTime time.Time `yaml:"created_time"` + UpdatedTime time.Time `yaml:"updated_time"` + IsConflict int `yaml:"is_conflict"` + Latitude float64 `yaml:"latitude"` + Longitude float64 `yaml:"longitude"` + Altitude float64 `yaml:"altitude"` + Author string `yaml:"author"` + SourceUrl string `yaml:"source_url"` + IsTODO int `yaml:"is_todo"` + TODODue int `yaml:"todo_due"` + TODOCompleted int `yaml:"todo_completed"` + Source string `yaml:"source"` + SourceApplication string `yaml:"source_application"` + ApplicationData string `yaml:"application_data"` + Order int `yaml:"order"` + UserCreatedTime time.Time `yaml:"user_created_time"` + UserUpdatedTime time.Time `yaml:"user_updated_time"` + EncryptionCipherText string `yaml:"encryption_cipher_text"` + EncryptionApplied int `yaml:"encryption_applied"` + MarkupLanguage int `yaml:"markup_language"` + IsShared int `yaml:"is_shared"` + BodyHTML string `yaml:"body_html"` + // BaseURL is if `body_html` is provided and contains relative URLs, provide the `base_url` parameter too so that all the URLs can be converted to absolute ones. The base URL is basically where the HTML was fetched from, minus the query (everything after the '?'). For example if the original page was `https://stackoverflow.com/search?q=%5Bjava%5D+test`, the base URL is `https://stackoverflow.com/search`. + BaseUrl string `yaml:"base_url"` + // ImageDataUrl contains an image to attach to the note, in [Data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) format. + ImageDataUrl string `yaml:"image_data_url"` + // CropRect is, if an image is provided, you can also specify an optional rectangle that will be used to crop the image. In format `{ x: x, y: y, width: width, height: height }` + CropRect string `yaml:"crop_rect"` + Type ItemType `yaml:"type_"` +} + +// ItemType is a type of the note. Copied from readme/api.md +type ItemType int + +const ( + ItemTypeNote ItemType = 1 + ItemTypeFolder = 2 + ItemTypeSetting = 3 + ItemTypeResource = 4 + ItemTypeTag = 5 + ItemTypeNoteTag = 6 + ItemTypeSearch = 7 + ItemTypeAlarm = 8 + ItemTypeMasterKey = 9 + ItemTypeItemChange = 10 + ItemTypeNoteResource = 11 + ItemTypeResourceLocalState = 12 + ItemTypeRevision = 13 + ItemTypeMigration = 14 + ItemTypeSmartFilter = 15 +) + +func Parse(in string) (Note, error) { + var title, body, params string + titleIdx := strings.Index(in, "\n\n") + paramsIdx := strings.LastIndex(in, "\n\n") + title, body, params = in[0:titleIdx], in[min(titleIdx+2, paramsIdx):paramsIdx], in[paramsIdx:] + + var note Note + if err := yaml.Unmarshal([]byte(params), &note); err != nil { + return Note{}, err + } + + note.Title = title + note.Body = body + + return note, nil +} + +func min(a, b int) int { + if a < b { + return a + } + return b +} diff --git a/src/joplin2site/internal/note/parse_test.go b/src/joplin2site/internal/note/note_test.go diff --git a/src/joplin2site/internal/note/parse.go b/src/joplin2site/internal/note/parse.go @@ -1,31 +0,0 @@ -package note - -import ( - "strings" - - "gopkg.in/yaml.v2" -) - -func Parse(in string) (Note, error) { - var title, body, params string - titleIdx := strings.Index(in, "\n\n") - paramsIdx := strings.LastIndex(in, "\n\n") - title, body, params = in[0:titleIdx], in[min(titleIdx+2, paramsIdx):paramsIdx], in[paramsIdx:] - - var note Note - if err := yaml.Unmarshal([]byte(params), &note); err != nil { - return Note{}, err - } - - note.Title = title - note.Body = body - - return note, nil -} - -func min(a, b int) int { - if a < b { - return a - } - return b -} diff --git a/src/joplin2site/internal/note/types.go b/src/joplin2site/internal/note/types.go @@ -1,61 +0,0 @@ -package note - -import "time" - -// Note is how Joplin understands the note. -type Note struct { - ID string `yaml:"id"` - ParentID string `yaml:"parent_id"` - Title string `yaml:"-"` - Body string `yaml:"-"` - CreatedTime time.Time `yaml:"created_time"` - UpdatedTime time.Time `yaml:"updated_time"` - IsConflict int `yaml:"is_conflict"` - Latitude float64 `yaml:"latitude"` - Longitude float64 `yaml:"longitude"` - Altitude float64 `yaml:"altitude"` - Author string `yaml:"author"` - SourceUrl string `yaml:"source_url"` - IsTODO int `yaml:"is_todo"` - TODODue int `yaml:"todo_due"` - TODOCompleted int `yaml:"todo_completed"` - Source string `yaml:"source"` - SourceApplication string `yaml:"source_application"` - ApplicationData string `yaml:"application_data"` - Order int `yaml:"order"` - UserCreatedTime time.Time `yaml:"user_created_time"` - UserUpdatedTime time.Time `yaml:"user_updated_time"` - EncryptionCipherText string `yaml:"encryption_cipher_text"` - EncryptionApplied int `yaml:"encryption_applied"` - MarkupLanguage int `yaml:"markup_language"` - IsShared int `yaml:"is_shared"` - BodyHTML string `yaml:"body_html"` - // BaseURL is if `body_html` is provided and contains relative URLs, provide the `base_url` parameter too so that all the URLs can be converted to absolute ones. The base URL is basically where the HTML was fetched from, minus the query (everything after the '?'). For example if the original page was `https://stackoverflow.com/search?q=%5Bjava%5D+test`, the base URL is `https://stackoverflow.com/search`. - BaseUrl string `yaml:"base_url"` - // ImageDataUrl contains an image to attach to the note, in [Data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) format. - ImageDataUrl string `yaml:"image_data_url"` - // CropRect is, if an image is provided, you can also specify an optional rectangle that will be used to crop the image. In format `{ x: x, y: y, width: width, height: height }` - CropRect string `yaml:"crop_rect"` - Type ItemType `yaml:"type_"` -} - -// ItemType is a type of the note. Copied from readme/api.md -type ItemType int - -const ( - ItemTypeNote ItemType = 1 - ItemTypeFolder = 2 - ItemTypeSetting = 3 - ItemTypeResource = 4 - ItemTypeTag = 5 - ItemTypeNoteTag = 6 - ItemTypeSearch = 7 - ItemTypeAlarm = 8 - ItemTypeMasterKey = 9 - ItemTypeItemChange = 10 - ItemTypeNoteResource = 11 - ItemTypeResourceLocalState = 12 - ItemTypeRevision = 13 - ItemTypeMigration = 14 - ItemTypeSmartFilter = 15 -)