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
|
||||
language string
|
||||
translationKey string
|
||||
images []string
|
||||
audio string
|
||||
filename string
|
||||
location string
|
||||
token string
|
||||
|
@ -92,8 +94,6 @@ func createEntryFromValueMap(values map[string][]string) (*Entry, error) {
|
|||
entry.tags = category
|
||||
} else if categories, ok := values["category[]"]; ok {
|
||||
entry.tags = categories
|
||||
} else {
|
||||
entry.tags = nil
|
||||
}
|
||||
if slug, ok := values["mp-slug"]; ok && len(slug) > 0 && slug[0] != "" {
|
||||
entry.slug = slug[0]
|
||||
|
@ -111,8 +111,16 @@ func createEntryFromValueMap(values map[string][]string) (*Entry, error) {
|
|||
entry.syndicate = syndicate
|
||||
} else if syndicates, ok := values["mp-syndicate-to[]"]; ok {
|
||||
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 {
|
||||
entry.token = "Bearer " + token[0]
|
||||
|
@ -153,6 +161,12 @@ func createEntryFromMicroformat(mfEntry *MicroformatItem) (*Entry, error) {
|
|||
if len(mfEntry.Properties.MpSyndicateTo) > 0 {
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -202,11 +216,23 @@ func computeExtraSettings(entry *Entry) error {
|
|||
} else if strings.HasPrefix(text, "translationkey: ") {
|
||||
// Translation key
|
||||
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 {
|
||||
_, _ = fmt.Fprintln(&filteredContent, text)
|
||||
}
|
||||
}
|
||||
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
|
||||
if len(entry.slug) == 0 || entry.slug == "" {
|
||||
random := generateRandomString(now, 5)
|
||||
|
|
|
@ -17,4 +17,6 @@ type MicroformatProperties struct {
|
|||
BookmarkOf []string `json:"bookmark-of,omitempty"`
|
||||
MpSlug []string `json:"mp-slug,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"`
|
||||
Syndicate []string `yaml:"syndicate,omitempty"`
|
||||
TranslationKey string `yaml:"translationKey,omitempty"`
|
||||
Images []string `yaml:"images,omitempty"`
|
||||
Audio string `yaml:"audio,omitempty"`
|
||||
}
|
||||
|
||||
type HugoFrontmatterIndieweb struct {
|
||||
|
@ -53,6 +55,8 @@ func writeFrontMatter(entry *Entry) (frontmatter string, err error) {
|
|||
},
|
||||
Syndicate: entry.syndicate,
|
||||
TranslationKey: entry.translationKey,
|
||||
Images: entry.images,
|
||||
Audio: entry.audio,
|
||||
}
|
||||
yamlBytes, err := yaml.Marshal(&writeFrontmatter)
|
||||
if err != nil {
|
||||
|
@ -118,6 +122,12 @@ func readFrontMatter(frontmatter string, entry *Entry) (err error) {
|
|||
if len(parsedFrontmatter.TranslationKey) > 0 {
|
||||
entry.translationKey = parsedFrontmatter.TranslationKey
|
||||
}
|
||||
if len(parsedFrontmatter.Images) > 0 {
|
||||
entry.images = parsedFrontmatter.Images
|
||||
}
|
||||
if len(parsedFrontmatter.Audio) > 0 {
|
||||
entry.audio = parsedFrontmatter.Audio
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue