pkg

package
v1.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TagsProp     = "Tags"
	PositionProp = "Position"
)
View Source
const Bilibili = "bilibili.com"
View Source
const Gist = "gist.github.com"
View Source
const Jsfiddle = "jsfiddle.net"
View Source
const RegexBili = `((?<=\.com\/video\/).*(?=\/))|((?<=bvid=).*(?=&cid?))`
View Source
const RegexJsfiddle = `(?<=jsfiddle\.net\/).*(?=\/)`
View Source
const RegexTwitterId = `(?<=status\/).*(?=\?)`
View Source
const RegexTwitterUser = `(?<=com\/).*(?=\/status)`
View Source
const RegexYoutube = `(?<=\.com\/watch\?v=).*`
View Source
const Twitter = "twitter.com"

Variables

View Source
var ColorMap = map[string]string{
	"gray":              grayColor,
	"brown":             brownColor,
	"orange":            orangeColor,
	"yellow":            yellowColor,
	"green":             greenColor,
	"blue":              blueColor,
	"purple":            purpleColor,
	"pink":              pinkColor,
	"red":               redColor,
	"gray_background":   grayBackground,
	"brown_background":  brownBackground,
	"orange_background": orangeBackground,
	"yellow_background": yellowBackground,
	"green_background":  greenBackground,
	"blue_background":   blueBackground,
	"purple_background": purpleBackground,
	"pink_background":   pinkBackground,
	"red_background":    redBackground,
}

Functions

func CamelCaseToUnderscore

func CamelCaseToUnderscore(s string) string

func ConvertRich

func ConvertRich(t notion.RichText) string

func ConvertRichText

func ConvertRichText(t []notion.RichText) string

func ConvertRow

func ConvertRow(r *notion.TableRowBlock, fmt string) string

func ConvertTable

func ConvertTable(rows []notion.Block) string

func DefaultConfigInit

func DefaultConfigInit() error

func FindTextP

func FindTextP(ori string, pre string) string

func FindUrlContext

func FindUrlContext(regex string, url string) string

func GetBlockType

func GetBlockType(block any) string

func HasEmpty

func HasEmpty(s string) bool

func RemoveSuffix

func RemoveSuffix(str string) (string, error)

func Run

func Run(ns *NotionSite) error

Types

type Config

type Config struct {
	Notion   `yaml:"notion"`
	Markdown `yaml:"markdown"`
}

type Files

type Files struct {
	Permission               uint32
	MediaPath                string
	Position                 string
	FileName                 string
	FileFolderPath           string
	FilePath                 string
	HomePath                 string
	DefaultMarkdownName      string
	DefaultMediaFolderName   string
	DefaultGalleryFolderName string

	CurrentNTPL string
	// contains filtered or unexported fields
}

func NewFiles

func NewFiles(config Config) (files *Files)

func (*Files) DownloadMedia

func (files *Files) DownloadMedia(dynamicMedia any) error

type FrontMatter

type FrontMatter struct {
	Title           string   `json:"title"           yaml:"title,flow"`
	Status          string   `json:"status"          yaml:"status,flow"`
	Author          string   `json:"author"          yaml:"author,flow"`
	Weight          int64    `json:"weight"          yaml:"weight,flow"`
	LastMod         string   `json:"lastMod"         yaml:"lastMod,flow"`
	CreateAt        string   `json:"createAt"        yaml:"createAt,flow"`
	ExpiryDate      string   `json:"expiryDate"      yaml:"expiryDate,flow"`
	Draft           bool     `json:"draft"           yaml:"draft,flow"`
	IsTranslated    bool     `json:"isTranslated"    yaml:"isTranslated,flow"`
	ShowComments    bool     `json:"showComments"    yaml:"showComments,flow"`
	Tags            []string `json:"tags"            yaml:"tags,flow"`
	Keywords        []string `json:"keywords"        yaml:"keywords,flow"`
	Categories      []string `json:"categories"      yaml:"categories,flow"`
	Slug            string   `json:"slug"            yaml:"slug,flow"`
	Image           string   `json:"image"           yaml:"image,flow"`
	Avatar          string   `json:"avatar"          yaml:"avatar,flow"`
	Position        string   `json:"position"        yaml:"position,flow"`
	AccessPath      string   `json:"accessPath"      yaml:"accessPath,flow"`
	Description     string   `json:"description"     yaml:"description,flow"`
	MetaTitle       string   `json:"metaTitle"       yaml:"metaTitle,flow"`
	MetaDescription string   `json:"metaDescription" yaml:"metaDescription,flow"`
}

type Markdown

type Markdown struct {
	HomePath        string `yaml:"homePath"`
	ImagePublicLink string `yaml:"imagePublicLink"`

	// Optional:
	GroupByMonth bool   `yaml:"groupByMonth,omitempty"`
	Template     string `yaml:"template,omitempty"`
}

type MdBlock

type MdBlock struct {
	notion.Block

	Depth int
	Extra map[string]any
	// contains filtered or unexported fields
}

type MediaBlock

type MediaBlock struct {
	notion.ImageBlock
	notion.VideoBlock
	notion.PDFBlock
	notion.AudioBlock
	notion.FileBlock
}

type Notion

type Notion struct {
	DatabaseID     string   `yaml:"databaseId"`
	FilterProp     string   `yaml:"filterProp"`
	FilterValue    []string `yaml:"filterValue"`
	PublishedValue string   `yaml:"publishedValue"`
}

type NotionAPI

type NotionAPI struct {
	Client *notion.Client
}

func NewAPI

func NewAPI() *NotionAPI

func (*NotionAPI) CheckHasChildDataBase

func (api *NotionAPI) CheckHasChildDataBase(blocks []notion.Block, cb func(bool, string)) bool

func (*NotionAPI) FindBlockChildrenCommentLoop

func (api *NotionAPI) FindBlockChildrenCommentLoop(client *notion.Client, blockArr []notion.Block, cursor string) (blocks []notion.Comment, err error)

type NotionCache

type NotionCache struct {
	ParentPropInfo  *NotionProp
	ParentFilesInfo *Files
	ChildDatabaseId string
}

func NewNotionCaches

func NewNotionCaches() []*NotionCache

type NotionCaches

type NotionCaches struct {
	TODO []*NotionCache
}

func (*NotionCaches) SetCache

func (caches *NotionCaches) SetCache(blockId string)

type NotionProp

type NotionProp struct {
	Name             string
	Title            string
	Status           string
	Categories       []string
	Tags             []string
	Position         string
	FileName         string
	Description      string
	CreateAt         *time.Time
	Author           string
	Avatar           string
	LastMod          time.Time
	ExpiryDate       time.Time
	PublishDate      time.Time
	ShowComments     *bool
	Slug             string
	Types            string
	IsSettingFile    bool
	IsCustomNameFile bool
}

func NewNotionProp

func NewNotionProp(page notion.Page) (np *NotionProp)

func (*NotionProp) GetFileName

func (np *NotionProp) GetFileName() string

func (*NotionProp) GetTitle

func (np *NotionProp) GetTitle() (title string)

func (*NotionProp) IsCustomNameMdFile

func (np *NotionProp) IsCustomNameMdFile() bool

IsCustomNameMdFile no setting type but has custom file name

func (*NotionProp) IsFolder

func (np *NotionProp) IsFolder() bool

func (*NotionProp) IsSetting

func (np *NotionProp) IsSetting() bool

type NotionSite

type NotionSite struct {
	// contains filtered or unexported fields
}

func NewNotionSite

func NewNotionSite(api *NotionAPI, tm *ToMarkdown, files *Files, config Config, caches []*NotionCache) *NotionSite

func (*NotionSite) SetFileInfo

func (ns *NotionSite) SetFileInfo(position string)

type ToMarkdown

type ToMarkdown struct {
	NotionProps       *NotionProp
	Files             *Files
	FrontMatter       map[string]any
	ContentBuffer     *bytes.Buffer
	ImgSavePath       string
	ImgVisitPath      string
	ArticleFolderPath string
	ContentTemplate   string
	// contains filtered or unexported fields
}

func New

func New() *ToMarkdown

func (*ToMarkdown) EnableExtendedSyntax

func (tm *ToMarkdown) EnableExtendedSyntax(target string)

func (*ToMarkdown) ExtendedSyntaxEnabled

func (tm *ToMarkdown) ExtendedSyntaxEnabled() bool

func (*ToMarkdown) GenBlock

func (tm *ToMarkdown) GenBlock(bType string, block MdBlock, addMoreTag bool, skip bool) error

GenBlock notion to hugo shortcodes template

func (*ToMarkdown) GenContentBlocks

func (tm *ToMarkdown) GenContentBlocks(blocks []notion.Block, depth int) error

func (*ToMarkdown) GenFrontMatter

func (tm *ToMarkdown) GenFrontMatter(writer io.Writer) (*FrontMatter, error)

func (*ToMarkdown) GenerateTo

func (tm *ToMarkdown) GenerateTo(ns *NotionSite) (*FrontMatter, error)

func (*ToMarkdown) WithFrontMatter

func (tm *ToMarkdown) WithFrontMatter(page notion.Page)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL