-
Notifications
You must be signed in to change notification settings - Fork 85
/
block.go
778 lines (675 loc) · 20.4 KB
/
block.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
package notionapi
import (
"fmt"
"sort"
"strings"
"time"
)
const (
// BlockAudio is audio embed (e.g. an mp3 file)
BlockAudio = "audio"
// BlockBookmark is a bookmark block
BlockBookmark = "bookmark"
// BlockBreadcrumb is breadcrumb block
BlockBreadcrumb = "breadcrumb"
// BlockBulletedList is a bulleted list block
BlockBulletedList = "bulleted_list"
// BlockCode is a code block
BlockCode = "code"
// BlockCodepen is embedded codepen block
BlockCodepen = "codepen"
// BlockCallout is a callout
BlockCallout = "callout"
// BlockColumn is a child of TypeColumnList
BlockColumn = "column"
// BlockColumnList is for multi-column. Number of columns is
// number of content blocks of type TypeColumn
BlockColumnList = "column_list"
// BlockCollectionView is a collection view block for inline collections
BlockCollectionView = "collection_view"
// BlockCollectionViewPage is a page that is a collection
BlockCollectionViewPage = "collection_view_page"
// BlockComment is a comment block
BlockComment = "comment"
// BlockDivider is a divider block
BlockDivider = "divider"
// BlockDrive is embedded Google Drive file
BlockDrive = "drive"
// BlockEmbed is a generic oembed link
BlockEmbed = "embed"
// BlockEquation is TeX equation block
BlockEquation = "equation"
// BlockFactory represents a factory block
BlockFactory = "factory"
// BlockFigma represents figma embed
BlockFigma = "figma"
// BlockFile is an embedded file
BlockFile = "file"
// BlockGist is embedded gist block
BlockGist = "gist"
// BlockHeader is a header block
BlockHeader = "header"
// BlockImage is an image block
BlockImage = "image"
// BlockMaps is embedded Google Map block
BlockMaps = "maps"
// BlockNumberedList is a numbered list block
BlockNumberedList = "numbered_list"
// BlockPDF is an embedded pdf file
BlockPDF = "pdf"
// BlockPage is a notion Page
BlockPage = "page"
// BlockQuote is a quote block
BlockQuote = "quote"
// BlockSubHeader is a header block
BlockSubHeader = "sub_header"
// BlockSubSubHeader
BlockSubSubHeader = "sub_sub_header"
// BlockTableOfContents is table of contents
BlockTableOfContents = "table_of_contents"
// BlockText is a text block
BlockText = "text"
// BlockTodo is a todo block
BlockTodo = "to_do"
// BlockToggle is a toggle block
BlockToggle = "toggle"
// BlockTweet is embedded gist block
BlockTweet = "tweet"
// BlockVideo is youtube video embed
BlockVideo = "video"
BlockCopyIndicator = "copy_indicator"
BlockLinkToCollection = "link_to_collection"
BlockLinkToPage = "link_to_page"
BlockMiro = "miro"
BlockAlias = "alias"
BlockTransclusionReference = "transclusion_reference"
)
// FormatBookmark describes format for BlockBookmark
type FormatBookmark struct {
BlockColor string `json:"block_color"`
Cover string `json:"bookmark_cover"`
Icon string `json:"bookmark_icon"`
}
// FormatBulletedList describes format for BlockBulletedList
type FormatBulletedList struct {
BlockColor string `json:"block_color"`
}
// FormatCallout describes format for BlockCallout
type FormatCallout struct {
BlockColor string `json:"block_color"`
Icon string `json:"bookmark_icon"`
}
// FormatCode describes format for BlockCode
type FormatCode struct {
CodeWrap bool `json:"code_wrap"`
}
type FormatCodepen struct {
BlockFullWidth bool `json:"block_full_width"`
BlockHeight float64 `json:"block_height"`
BlockPageWidth bool `json:"block_page_width"`
BlockPreserveScale bool `json:"block_preserve_scale"`
BlockWidth float64 `json:"block_width"`
DisplaySource string `json:"display_source,omitempty"`
}
type FormatCollectionView struct {
BlockFullWidth bool `json:"block_full_width"`
BlockHeight float64 `json:"block_height"`
BlockPageWidth bool `json:"block_page_width"`
BlockWidth float64 `json:"block_width"`
}
// FormatColumn describes format for BlockColumn
type FormatColumn struct {
// e.g. 0.5 for half-sized column
ColumnRatio float64 `json:"column_ratio"`
}
type DriveProperties struct {
FileID string `json:"file_id"`
Icon string `json:"icon"`
ModifiedTime int64 `json:"modified_time"`
Thumbnail string `json:"thumbnail"` // url
Title string `json:"title"`
Trashed bool `json:"trashed"`
URL string `json:"url"`
UserName string `json:"user_name"`
Version int `json:"version"`
}
type DriveStatus struct {
Authed bool `json:"authed"`
LastFetched int64 `json:"last_fetched"`
}
type FormatDrive struct {
DriveProperties *DriveProperties `json:"drive_properties"`
DriveStatus *DriveStatus `json:"drive_status"`
}
// FormatEmbed describes format for BlockEmbed
type FormatEmbed struct {
BlockFullWidth bool `json:"block_full_width"`
BlockHeight float64 `json:"block_height"`
BlockPageWidth bool `json:"block_page_width"`
BlockPreserveScale bool `json:"block_preserve_scale"`
BlockWidth float64 `json:"block_width"`
DisplaySource string `json:"display_source"`
}
type AliasPointer struct {
ID string `json:"id"`
SpaceID string `json:"spaceId"`
Table string `json:"table"`
}
// FormatAlias describes format for BlockAlias
type FormatAlias struct {
Alias *AliasPointer `json:"alias_pointer"`
}
type FormatFigma struct {
BlockFullWidth bool `json:"block_full_width"`
BlockHeight float64 `json:"block_height"`
BlockPageWidth bool `json:"block_page_width"`
BlockPreserveScale bool `json:"block_preserve_scale"`
BlockWidth float64 `json:"block_width"`
DisplaySource string `json:"display_source"`
}
// FormatHeader describes format for BlockHeader, BlockSubHeader, BlockSubSubHeader
type FormatHeader struct {
BlockColor string `json:"block_color,omitempty"`
}
// FormatImage describes format for BlockImage
type FormatImage struct {
// comes from notion API
BlockAspectRatio float64 `json:"block_aspect_ratio"`
BlockFullWidth bool `json:"block_full_width"`
BlockHeight float64 `json:"block_height"`
BlockPageWidth bool `json:"block_page_width"`
BlockPreserveScale bool `json:"block_preserve_scale"`
BlockWidth float64 `json:"block_width"`
DisplaySource string `json:"display_source,omitempty"`
}
type FormatMaps struct {
BlockFullWidth bool `json:"block_full_width"`
BlockHeight float64 `json:"block_height"`
BlockPageWidth bool `json:"block_page_width"`
BlockPreserveScale bool `json:"block_preserve_scale"`
BlockWidth float64 `json:"block_width"`
DisplaySource string `json:"display_source,omitempty"`
}
// FormatNumberedList describes format for BlockNumberedList
type FormatNumberedList struct {
BlockColor string `json:"block_color"`
}
type CopiedFromPointer struct {
ID string `json:"id"`
Table string `json:"table"`
SpaceID string `json:"spaceId"`
}
// FormatPage describes format for BlockPage
type FormatPage struct {
// /images/page-cover/gradients_11.jpg
PageCover string `json:"page_cover"`
// e.g. 0.6
PageCoverPosition float64 `json:"page_cover_position"`
PageFont string `json:"page_font"`
PageFullWidth bool `json:"page_full_width"`
// it's url like https://s3-us-west-2.amazonaws.com/secure.notion-static.com/8b3930e3-9dfe-4ba7-a845-a8ff69154f2a/favicon-256.png
// or emoji like "✉️"
PageIcon string `json:"page_icon"`
PageSmallText bool `json:"page_small_text"`
BlockColor string `json:"block_color"`
BlockLocked bool `json:"block_locked"`
BlockLockedBy string `json:"block_locked_by"`
CopiedFromPointer *CopiedFromPointer `json:"copied_from_pointer"`
// calculated by us
PageCoverURL string `json:"page_cover_url,omitempty"`
}
type FormatPDF struct {
BlockFullWidth bool `json:"block_full_width"`
BlockHeight float64 `json:"block_height"`
BlockPageWidth bool `json:"block_page_width"`
BlockPreserveScale bool `json:"block_preserve_scale"`
BlockWidth float64 `json:"block_width"`
}
type FormatTableOfContents struct {
BlockColor string `json:"block_color,omitempty"`
}
// FormatText describes format for BlockText
type FormatText struct {
BlockColor string `json:"block_color,omitempty"`
}
// FormatToggle describes format for BlockToggle
type FormatToggle struct {
BlockColor string `json:"block_color"`
}
// FormatVideo describes fromat form BlockVideo
type FormatVideo struct {
BlockAspectRatio float64 `json:"block_aspect_ratio"`
BlockFullWidth bool `json:"block_full_width"`
BlockHeight int64 `json:"block_height"`
BlockPageWidth bool `json:"block_page_width"`
BlockPreserveScale bool `json:"block_preserve_scale"`
BlockWidth int64 `json:"block_width"`
DisplaySource string `json:"display_source"`
}
const (
// value of Permission.Type
PermissionUser = "user_permission"
PermissionPublic = "public_permission"
)
// Permission represents user permissions o
type Permission struct {
Type string `json:"type"`
// common to some permission types
Role interface{} `json:"role"`
// if Type == "user_permission"
UserID *string `json:"user_id,omitempty"`
AddedTimestamp int64 `json:"added_timestamp"`
// if Type == "public_permission"
AllowDuplicate bool `json:"allow_duplicate"`
AllowSearchEngineIndexing bool `json:"allow_search_engine_indexing"`
}
// Block describes a block
type Block struct {
// values that come from JSON
// a unique ID of the block
ID string `json:"id"`
// if false, the page is deleted
Alive bool `json:"alive"`
// List of block ids for that make up content of this block
// Use Content to get corresponding block (they are in the same order)
ContentIDs []string `json:"content,omitempty"`
CopiedFrom string `json:"copied_from,omitempty"`
CollectionID string `json:"collection_id,omitempty"` // for BlockCollectionView
// ID of the user who created this block
CreatedBy string `json:"created_by"`
CreatedTime int64 `json:"created_time"`
CreatedByTable string `json:"created_by_table"` // e.g. "notion_user"
CreatedByID string `json:"created_by_id"` // e.g. "bb760e2d-d679-4b64-b2a9-03005b21870a",
// ID of the user who last edited this block
LastEditedBy string `json:"last_edited_by"`
LastEditedTime int64 `json:"last_edited_time"`
LastEditedByTable string `json:"last_edited_by_table"` // e.g. "notion_user"
LastEditedByID string `json:"last_edited_by_id"` // e.g. "bb760e2d-d679-4b64-b2a9-03005b21870a"
// List of block ids with discussion content
DiscussionIDs []string `json:"discussion,omitempty"`
// those ids seem to map to storage in s3
// https://s3-us-west-2.amazonaws.com/secure.notion-static.com/${id}/${name}
FileIDs []string `json:"file_ids,omitempty"`
// TODO: don't know what this means
IgnoreBlockCount bool `json:"ignore_block_count,omitempty"`
// ID of parent Block
ParentID string `json:"parent_id"`
ParentTable string `json:"parent_table"`
// not always available
Permissions *[]Permission `json:"permissions,omitempty"`
Properties map[string]interface{} `json:"properties,omitempty"`
SpaceID string `json:"space_id"`
// type of the block e.g. TypeText, TypePage etc.
Type string `json:"type"`
// blocks are versioned
Version int64 `json:"version"`
// for BlockCollectionView
ViewIDs []string `json:"view_ids,omitempty"`
// Parent of this block
Parent *Block `json:"-"`
// maps ContentIDs array to Block type
Content []*Block `json:"-"`
// this is for some types like TypePage, TypeText, TypeHeader etc.
InlineContent []*TextSpan `json:"-"`
// for BlockPage
Title string `json:"-"`
// For BlockTodo, a checked state
IsChecked bool `json:"-"`
// for BlockBookmark
Description string `json:"-"`
Link string `json:"-"`
// for BlockBookmark it's the url of the page
// for BlockGist it's the url for the gist
// for BlockImage it's url of the image. Sometimes you need to use DownloadFile()
// to get this image
// for BlockFile it's url of the file
// for BlockEmbed it's url of the embed
Source string `json:"-"`
// for BlockFile
FileSize string `json:"-"`
// for BlockCode
Code string `json:"-"`
CodeLanguage string `json:"-"`
// for BlockCollectionView. There can be multiple views
// those correspond to ViewIDs
TableViews []*TableView `json:"-"`
// for BlockCollectionView without "collection_id" use ID from the CollectionPointer
Format struct {
CollectionPointer struct {
ID string `json:"id"`
SpaceID string `json:"spaceId"`
Table string `json:"table"`
} `json:"collection_pointer"`
PageIcon string `json:"page_icon"`
} `json:"format"`
Page *Page `json:"-"`
// RawJSON represents Block as
RawJSON map[string]interface{} `json:"-"`
notionID *NotionID
parentNotionID *NotionID
isResolved bool
}
func (b *Block) GetNotionID() *NotionID {
if b.notionID == nil {
b.notionID = NewNotionID(b.ID)
}
return b.notionID
}
func (b *Block) GetParentNotionID() *NotionID {
if b.parentNotionID == nil {
b.parentNotionID = NewNotionID(b.ParentID)
}
return b.parentNotionID
}
func (b *Block) Prop(key string) (interface{}, bool) {
parts := strings.Split(key, ".")
js := b.RawJSON
var ok bool
lastIdx := len(parts) - 1
for i := 0; i < lastIdx; i++ {
key = parts[i]
v := js[key]
if v == nil {
return nil, false
}
js, ok = v.(map[string]interface{})
if !ok {
return nil, false
}
}
key = parts[lastIdx]
v, ok := js[key]
return v, ok
}
func (b *Block) PropAsString(key string) (string, bool) {
v, ok := b.Prop(key)
if !ok || v == nil {
return "", false
}
s, ok := v.(string)
return s, ok
}
// CreatedOn return the time the page was created
func (b *Block) CreatedOn() time.Time {
return time.Unix(b.CreatedTime/1000, 0)
}
// LastEditedOn returns the time the page was last updated
func (b *Block) LastEditedOn() time.Time {
return time.Unix(b.LastEditedTime/1000, 0)
}
// IsLinkToPage returns true if block element is a link to a page
// (as opposed to embedded page)
func (b *Block) IsLinkToPage() bool {
if b.Type != BlockPage {
return false
}
return b.ParentTable == TableSpace
}
// IsSubPage returns true if this is a sub-page (as opposed to
// link to a page that is not a child of that page)
func (b *Block) IsSubPage() bool {
panicIf(b.Type != BlockPage)
if b.Parent == nil {
return false
}
return b.ParentID == b.Parent.ID
}
// IsPage returns true if block represents a page (either a
// sub-page or a link to a page)
func (b *Block) IsPage() bool {
return b.Type == BlockPage
}
// IsImage returns true if block represents an image
func (b *Block) IsImage() bool {
return b.Type == BlockImage
}
// IsCode returns true if block represents a code block
func (b *Block) IsCode() bool {
return b.Type == BlockCode
}
// IsEmbeddedType returns true if block represents an embedded type
func (b *Block) IsEmbeddedType() bool {
switch b.Type {
case BlockImage, BlockEmbed, BlockAudio,
BlockFile, BlockVideo:
return true
}
return false
}
func getProp(block *Block, name string, toSet *string) bool {
v, ok := block.Properties[name]
if !ok {
return false
}
s, err := getFirstInlineBlock(v)
if err != nil {
return false
}
*toSet = s
return true
}
func (b *Block) GetProperty(name string) []*TextSpan {
v, ok := b.Properties[name]
if !ok {
return nil
}
ts, err := ParseTextSpans(v)
if err != nil {
return nil
}
return ts
}
func (b *Block) GetCaption() []*TextSpan {
return b.GetProperty("caption")
}
func (b *Block) GetTitle() []*TextSpan {
return b.GetProperty("title")
}
func parseTitle(block *Block) error {
// has already been parsed
if block.InlineContent != nil {
return nil
}
props := block.Properties
title, ok := props["title"]
if !ok {
return nil
}
var err error
block.InlineContent, err = ParseTextSpans(title)
if err != nil {
return err
}
switch block.Type {
case BlockPage, BlockFile, BlockBookmark:
block.Title, err = getInlineText(title)
case BlockCode:
block.Code, err = getInlineText(title)
default:
}
return err
}
func parseProperties(block *Block) error {
err := parseTitle(block)
if err != nil {
return err
}
props := block.Properties
if BlockTodo == block.Type {
if checked, ok := props["checked"]; ok {
s, _ := getFirstInlineBlock(checked)
// fmt.Printf("checked: '%s'\n", s)
block.IsChecked = strings.EqualFold(s, "Yes")
}
}
// for BlockBookmark
getProp(block, "description", &block.Description)
// for BlockBookmark
getProp(block, "link", &block.Link)
// for BlockBookmark, BlockImage, BlockGist, BlockFile, BlockEmbed
// don't over-write if was already set from "source" json field
if block.Source == "" {
getProp(block, "source", &block.Source)
}
// for BlockCode
getProp(block, "language", &block.CodeLanguage)
// for BlockFile
if block.Type == BlockFile {
getProp(block, "size", &block.FileSize)
}
return nil
}
func (b *Block) panicIfNotOfType(expectedType string) {
if b.Type != expectedType {
panic(fmt.Sprintf("operation on invalid block. Block type: %s, expected type: %s", b.Type, expectedType))
}
}
func (b *Block) unmarshalFormat(expectedType string, v interface{}) bool {
b.panicIfNotOfType(expectedType)
formatRaw := jsonGetMap(b.RawJSON, "format")
if len(formatRaw) == 0 {
return false
}
err := jsonUnmarshalFromMap(formatRaw, v)
if err != nil {
panic(err)
}
return true
}
func (b *Block) FormatBookmark() *FormatBookmark {
var format FormatBookmark
if ok := b.unmarshalFormat(BlockBookmark, &format); !ok {
return nil
}
return &format
}
// FormatPage returns decoded format property for BlockPage
// TODO: maybe separate FormatCollectionViewPage
func (b *Block) FormatPage() *FormatPage {
var format FormatPage
if b.Type == BlockPage {
if ok := b.unmarshalFormat(BlockPage, &format); !ok {
return nil
}
} else if b.Type == BlockCollectionViewPage {
if ok := b.unmarshalFormat(BlockCollectionViewPage, &format); !ok {
return nil
}
} else {
b.panicIfNotOfType(BlockPage)
}
return &format
}
func (b *Block) FormatImage() *FormatImage {
var format FormatImage
if ok := b.unmarshalFormat(BlockImage, &format); !ok {
return nil
}
return &format
}
func (b *Block) FormatColumn() *FormatColumn {
var format FormatColumn
if ok := b.unmarshalFormat(BlockColumn, &format); !ok {
return nil
}
return &format
}
func (b *Block) FormatText() *FormatText {
var format FormatText
if ok := b.unmarshalFormat(BlockText, &format); !ok {
return nil
}
return &format
}
func (b *Block) FormatVideo() *FormatVideo {
var format FormatVideo
if ok := b.unmarshalFormat(BlockVideo, &format); !ok {
return nil
}
return &format
}
func (b *Block) FormatAlias() *FormatAlias {
var format FormatAlias
if ok := b.unmarshalFormat(BlockAlias, &format); !ok {
return nil
}
return &format
}
func (b *Block) FormatEmbed() *FormatEmbed {
var format FormatEmbed
if ok := b.unmarshalFormat(BlockEmbed, &format); !ok {
return nil
}
return &format
}
func (b *Block) FormatHeader() *FormatHeader {
var format FormatHeader
if ok := b.unmarshalFormat(BlockHeader, &format); !ok {
return nil
}
return &format
}
func (b *Block) FormatToggle() *FormatToggle {
var format FormatToggle
if ok := b.unmarshalFormat(BlockToggle, &format); !ok {
return nil
}
return &format
}
func (b *Block) FormatNumberedList() *FormatNumberedList {
var format FormatNumberedList
if ok := b.unmarshalFormat(BlockNumberedList, &format); !ok {
return nil
}
return &format
}
func (b *Block) FormatBulletedList() *FormatBulletedList {
var format FormatBulletedList
if ok := b.unmarshalFormat(BlockBulletedList, &format); !ok {
return nil
}
return &format
}
func (b *Block) FormatCallout() *FormatCallout {
var format FormatCallout
if ok := b.unmarshalFormat(BlockCallout, &format); !ok {
return nil
}
return &format
}
func (b *Block) FixCollectionID() string {
if b.CollectionID != "" {
return b.CollectionID
}
if b.Format.CollectionPointer.ID != "" {
return b.Format.CollectionPointer.ID
}
return ""
}
func (b *Block) BlockByID(nid *NotionID) *Block {
return b.Page.BlockByID(nid)
}
func (b *Block) NotionUserByID(nid *NotionID) *NotionUser {
return b.Page.NotionUserByID(nid)
}
func (b *Block) CollectionByID(nid *NotionID) *Collection {
return b.Page.CollectionByID(nid)
}
func (b *Block) CollectionViewByID(nid *NotionID) *CollectionView {
return b.Page.CollectionViewByID(nid)
}
func getBlockIDsSorted(idToBlock map[string]*Block) []string {
// we want to serialize in a fixed order
n := len(idToBlock)
if n == 0 {
return nil
}
ids := make([]string, n)
i := 0
for id := range idToBlock {
ids[i] = id
i++
}
sort.Strings(ids)
return ids
}