|
|
@@ -30,13 +30,18 @@ type Entry struct { |
|
|
|
syndicate []string |
|
|
|
language string |
|
|
|
translationKey string |
|
|
|
images []string |
|
|
|
images []Image |
|
|
|
audio string |
|
|
|
filename string |
|
|
|
location string |
|
|
|
token string |
|
|
|
} |
|
|
|
|
|
|
|
type Image struct { |
|
|
|
url string |
|
|
|
alt string |
|
|
|
} |
|
|
|
|
|
|
|
func CreateEntry(contentType ContentType, r *http.Request) (*Entry, error) { |
|
|
|
if contentType == WwwForm { |
|
|
|
bodyString, err := parseRequestBody(r) |
|
|
@@ -113,9 +118,22 @@ func createEntryFromValueMap(values map[string][]string) (*Entry, error) { |
|
|
|
entry.syndicate = syndicates |
|
|
|
} |
|
|
|
if photo, ok := values["photo"]; ok { |
|
|
|
entry.images = photo |
|
|
|
} else if photo, ok := values["photo[]"]; ok { |
|
|
|
entry.images = photo |
|
|
|
entry.images = append(entry.images, Image{url: photo[0]}) |
|
|
|
} else if photos, ok := values["photo[]"]; ok { |
|
|
|
for _, photo := range photos { |
|
|
|
entry.images = append(entry.images, Image{url: photo}) |
|
|
|
} |
|
|
|
} |
|
|
|
if photoAlt, ok := values["mp-photo-alt"]; ok { |
|
|
|
if len(entry.images) > 0 { |
|
|
|
entry.images[0].alt = photoAlt[0] |
|
|
|
} |
|
|
|
} else if photoAlts, ok := values["mp-photo-alt[]"]; ok { |
|
|
|
for i, photoAlt := range photoAlts { |
|
|
|
if len(entry.images) > i { |
|
|
|
entry.images[i].alt = photoAlt |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if audio, ok := values["audio"]; ok { |
|
|
|
entry.audio = audio[0] |
|
|
@@ -162,7 +180,21 @@ func createEntryFromMicroformat(mfEntry *MicroformatItem) (*Entry, error) { |
|
|
|
entry.syndicate = mfEntry.Properties.MpSyndicateTo |
|
|
|
} |
|
|
|
if len(mfEntry.Properties.Photo) > 0 { |
|
|
|
entry.images = mfEntry.Properties.Photo |
|
|
|
for _, photo := range mfEntry.Properties.Photo { |
|
|
|
if theString, justString := photo.(string); justString { |
|
|
|
entry.images = append(entry.images, Image{url: theString}) |
|
|
|
} else if thePhoto, isPhoto := photo.(map[string]interface{}); isPhoto { |
|
|
|
image := Image{} |
|
|
|
// Micropub spec says "value" is correct, but not sure about that |
|
|
|
if photoUrl, ok := thePhoto["value"].(string); ok { |
|
|
|
image.url = photoUrl |
|
|
|
} |
|
|
|
if alt, ok := thePhoto["alt"].(string); ok { |
|
|
|
image.alt = alt |
|
|
|
} |
|
|
|
entry.images = append(entry.images, image) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if len(mfEntry.Properties.Audio) > 0 { |
|
|
|
entry.audio = mfEntry.Properties.Audio[0] |
|
|
@@ -218,7 +250,9 @@ func computeExtraSettings(entry *Entry) error { |
|
|
|
entry.translationKey = strings.TrimPrefix(text, "translationkey: ") |
|
|
|
} else if strings.HasPrefix(text, "images: ") { |
|
|
|
// Images |
|
|
|
entry.images = strings.Split(strings.TrimPrefix(text, "images: "), ",") |
|
|
|
for _, image := range strings.Split(strings.TrimPrefix(text, "images: "), ",") { |
|
|
|
entry.images = append(entry.images, Image{url: image}) |
|
|
|
} |
|
|
|
} else if strings.HasPrefix(text, "audio: ") { |
|
|
|
// Audio |
|
|
|
entry.audio = strings.TrimPrefix(text, "audio: ") |
|
|
@@ -229,8 +263,12 @@ func computeExtraSettings(entry *Entry) error { |
|
|
|
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\n" |
|
|
|
if !strings.Contains(entry.content, image.url) { |
|
|
|
if len(image.alt) > 0 { |
|
|
|
entry.content += "\n\n" |
|
|
|
} else { |
|
|
|
entry.content += "\n\n" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// Compute slug if empty |
|
|
|