Add support for images and audio
parent
108571ac15
commit
962818c931
34
entry.go
34
entry.go
|
@ -30,6 +30,8 @@ type Entry struct {
|
||||||
syndicate []string
|
syndicate []string
|
||||||
language string
|
language string
|
||||||
translationKey string
|
translationKey string
|
||||||
|
images []string
|
||||||
|
audio string
|
||||||
filename string
|
filename string
|
||||||
location string
|
location string
|
||||||
token string
|
token string
|
||||||
|
@ -92,8 +94,6 @@ func createEntryFromValueMap(values map[string][]string) (*Entry, error) {
|
||||||
entry.tags = category
|
entry.tags = category
|
||||||
} else if categories, ok := values["category[]"]; ok {
|
} else if categories, ok := values["category[]"]; ok {
|
||||||
entry.tags = categories
|
entry.tags = categories
|
||||||
} else {
|
|
||||||
entry.tags = nil
|
|
||||||
}
|
}
|
||||||
if slug, ok := values["mp-slug"]; ok && len(slug) > 0 && slug[0] != "" {
|
if slug, ok := values["mp-slug"]; ok && len(slug) > 0 && slug[0] != "" {
|
||||||
entry.slug = slug[0]
|
entry.slug = slug[0]
|
||||||
|
@ -111,8 +111,16 @@ func createEntryFromValueMap(values map[string][]string) (*Entry, error) {
|
||||||
entry.syndicate = syndicate
|
entry.syndicate = syndicate
|
||||||
} else if syndicates, ok := values["mp-syndicate-to[]"]; ok {
|
} else if syndicates, ok := values["mp-syndicate-to[]"]; ok {
|
||||||
entry.syndicate = syndicates
|
entry.syndicate = syndicates
|
||||||
} else {
|
}
|
||||||
entry.syndicate = nil
|
if photo, ok := values["photo"]; ok {
|
||||||
|
entry.images = photo
|
||||||
|
} else if photo, ok := values["photo[]"]; ok {
|
||||||
|
entry.images = photo
|
||||||
|
}
|
||||||
|
if audio, ok := values["audio"]; ok {
|
||||||
|
entry.audio = audio[0]
|
||||||
|
} else if audio, ok := values["audio[]"]; ok {
|
||||||
|
entry.audio = audio[0]
|
||||||
}
|
}
|
||||||
if token, ok := values["access_token"]; ok {
|
if token, ok := values["access_token"]; ok {
|
||||||
entry.token = "Bearer " + token[0]
|
entry.token = "Bearer " + token[0]
|
||||||
|
@ -153,6 +161,12 @@ func createEntryFromMicroformat(mfEntry *MicroformatItem) (*Entry, error) {
|
||||||
if len(mfEntry.Properties.MpSyndicateTo) > 0 {
|
if len(mfEntry.Properties.MpSyndicateTo) > 0 {
|
||||||
entry.syndicate = mfEntry.Properties.MpSyndicateTo
|
entry.syndicate = mfEntry.Properties.MpSyndicateTo
|
||||||
}
|
}
|
||||||
|
if len(mfEntry.Properties.Photo) > 0 {
|
||||||
|
entry.images = mfEntry.Properties.Photo
|
||||||
|
}
|
||||||
|
if len(mfEntry.Properties.Audio) > 0 {
|
||||||
|
entry.audio = mfEntry.Properties.Audio[0]
|
||||||
|
}
|
||||||
err := computeExtraSettings(entry)
|
err := computeExtraSettings(entry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -202,11 +216,23 @@ func computeExtraSettings(entry *Entry) error {
|
||||||
} else if strings.HasPrefix(text, "translationkey: ") {
|
} else if strings.HasPrefix(text, "translationkey: ") {
|
||||||
// Translation key
|
// Translation key
|
||||||
entry.translationKey = strings.TrimPrefix(text, "translationkey: ")
|
entry.translationKey = strings.TrimPrefix(text, "translationkey: ")
|
||||||
|
} else if strings.HasPrefix(text, "images: ") {
|
||||||
|
// Images
|
||||||
|
entry.images = strings.Split(strings.TrimPrefix(text, "images: "), ",")
|
||||||
|
} else if strings.HasPrefix(text, "audio: ") {
|
||||||
|
// Audio
|
||||||
|
entry.audio = strings.TrimPrefix(text, "audio: ")
|
||||||
} else {
|
} else {
|
||||||
_, _ = fmt.Fprintln(&filteredContent, text)
|
_, _ = fmt.Fprintln(&filteredContent, text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entry.content = filteredContent.String()
|
entry.content = filteredContent.String()
|
||||||
|
// Check if content contains images or add them
|
||||||
|
for _, image := range entry.images {
|
||||||
|
if !strings.Contains(entry.content, image) {
|
||||||
|
entry.content += "\n![](" + image + ")\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
// Compute slug if empty
|
// Compute slug if empty
|
||||||
if len(entry.slug) == 0 || entry.slug == "" {
|
if len(entry.slug) == 0 || entry.slug == "" {
|
||||||
random := generateRandomString(now, 5)
|
random := generateRandomString(now, 5)
|
||||||
|
|
|
@ -17,4 +17,6 @@ type MicroformatProperties struct {
|
||||||
BookmarkOf []string `json:"bookmark-of,omitempty"`
|
BookmarkOf []string `json:"bookmark-of,omitempty"`
|
||||||
MpSlug []string `json:"mp-slug,omitempty"`
|
MpSlug []string `json:"mp-slug,omitempty"`
|
||||||
MpSyndicateTo []string `json:"mp-syndicate-to,omitempty"`
|
MpSyndicateTo []string `json:"mp-syndicate-to,omitempty"`
|
||||||
|
Photo []string `json:"photo,omitempty"`
|
||||||
|
Audio []string `json:"audio,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
10
post.go
10
post.go
|
@ -16,6 +16,8 @@ type HugoFrontmatter struct {
|
||||||
Indieweb HugoFrontmatterIndieweb `yaml:"indieweb,omitempty"`
|
Indieweb HugoFrontmatterIndieweb `yaml:"indieweb,omitempty"`
|
||||||
Syndicate []string `yaml:"syndicate,omitempty"`
|
Syndicate []string `yaml:"syndicate,omitempty"`
|
||||||
TranslationKey string `yaml:"translationKey,omitempty"`
|
TranslationKey string `yaml:"translationKey,omitempty"`
|
||||||
|
Images []string `yaml:"images,omitempty"`
|
||||||
|
Audio string `yaml:"audio,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type HugoFrontmatterIndieweb struct {
|
type HugoFrontmatterIndieweb struct {
|
||||||
|
@ -53,6 +55,8 @@ func writeFrontMatter(entry *Entry) (frontmatter string, err error) {
|
||||||
},
|
},
|
||||||
Syndicate: entry.syndicate,
|
Syndicate: entry.syndicate,
|
||||||
TranslationKey: entry.translationKey,
|
TranslationKey: entry.translationKey,
|
||||||
|
Images: entry.images,
|
||||||
|
Audio: entry.audio,
|
||||||
}
|
}
|
||||||
yamlBytes, err := yaml.Marshal(&writeFrontmatter)
|
yamlBytes, err := yaml.Marshal(&writeFrontmatter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -118,6 +122,12 @@ func readFrontMatter(frontmatter string, entry *Entry) (err error) {
|
||||||
if len(parsedFrontmatter.TranslationKey) > 0 {
|
if len(parsedFrontmatter.TranslationKey) > 0 {
|
||||||
entry.translationKey = parsedFrontmatter.TranslationKey
|
entry.translationKey = parsedFrontmatter.TranslationKey
|
||||||
}
|
}
|
||||||
|
if len(parsedFrontmatter.Images) > 0 {
|
||||||
|
entry.images = parsedFrontmatter.Images
|
||||||
|
}
|
||||||
|
if len(parsedFrontmatter.Audio) > 0 {
|
||||||
|
entry.audio = parsedFrontmatter.Audio
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue