Add youtube embeds to FB import

This commit is contained in:
JP Hastings-Spital 2024-04-04 17:32:51 +01:00
parent 0b509aa3a5
commit 2128658e67
2 changed files with 10 additions and 3 deletions

View file

@ -1,3 +1,4 @@
rtv2nwevsrb7jskkoi2niza6qq
tuoyt24xgoknswodnhizqehx2u
lsdjotoggybiqsetlzmwcpptay
b3atqewyj3xseyeu2tmyogss4e

View file

@ -34,6 +34,8 @@ func makePostPath(postType string, postDate time.Time, postHash string) string {
return path.Join("content", postType+"s", "facebook", postDate.Format("2006-01"), postHash)
}
var youtubeRE = regexp.MustCompile(`youtu(?:\.be/|be.com/watch\?v=)(.+)`)
func postize(e PostCheckinPhotoOrVideo, matches []string) (shared.Post, shared.MediaMap, bool, error) {
archiveRoot := matches[1]
@ -57,6 +59,11 @@ func postize(e PostCheckinPhotoOrVideo, matches []string) (shared.Post, shared.M
},
}
// Ignore my posts on others' walls
if strings.HasPrefix(post.FrontMatter.Title, "JP Hastings-Spital wrote on") {
return post, nil, true, nil
}
for _, attach := range e.Attachments {
linkURLs := attach.Data.GetSubstrings("external_context", "url")
for _, link := range linkURLs {
@ -111,9 +118,8 @@ func postize(e PostCheckinPhotoOrVideo, matches []string) (shared.Post, shared.M
post.PostFile = postFile
// Ignore my posts on others' walls
if strings.HasPrefix(post.FrontMatter.Title, "JP Hastings-Spital wrote on") {
return post, nil, true, nil
if match := youtubeRE.FindStringSubmatch(post.FrontMatter.BookmarkOf); len(match) > 1 {
post.PostFile = fmt.Sprintf("%s\n\n{{< youtube \"%s\" >}}", post.PostFile, match[1])
}
return post, mm, false, nil