diff --git a/tools/.archiveignore b/tools/.archiveignore index 0ec500a2..86865281 100644 --- a/tools/.archiveignore +++ b/tools/.archiveignore @@ -22,4 +22,18 @@ vbuyylvkpwofvk6w5ljf52fofq qewo2r2bmyayxaqwbgocdp7kb4 pmtarzxo6txmncvb7v2e7gycye le5h6ori75na7w23ald3ly45qa -b2fcvdtovbazjpctyb6eyt7oze \ No newline at end of file +b2fcvdtovbazjpctyb6eyt7oze +2ae7bof3qivs25v6xihoz42zza +aqcftuzb4kteqve6lluvhiewta +3vyrxpfyyuj4olq7ya4kgko7he +zlkpjo4sxqsbocej3nar5cw5kq +trmgu4muayrxcscn7bbcquozom +7sov3rxu3tqdi2t2dyfvyy35ge +bbwc5e4dlpt3q3kvh6yseq7uaa +pq4ukbww6klhvzyrzhsbzqzdf4 +poieboac65bjxse3flxrthvgvu +pta3typpd67kehasqmaj7daifa +55g6wdoiejvcyxa5k6du42zkya +42zuekfsg6zkjm5hz67svw3zju +62jzsu3hz2zmb2i5etez4unm3m +niucmeeuibtxl2pk4xpulr36mi diff --git a/tools/archive/facebook/exportfile.go b/tools/archive/facebook/exportfile.go index 5cd45c74..4764a45c 100644 --- a/tools/archive/facebook/exportfile.go +++ b/tools/archive/facebook/exportfile.go @@ -122,6 +122,10 @@ func postize(e PostCheckinPhotoOrVideo, matches []string) (shared.Post, shared.M post.Path = makePostPath("photo", postDate, postHash) mm[path.Join(archiveRoot, mediaPath)] = path.Join(post.Path, mediaName) } + + if loc, ok := attach.Data.GetLocation(); ok { + post.FrontMatter.Location = loc + } } postFile, err := formatPostText(e.Data.GetString("post"), e.Tags) diff --git a/tools/archive/facebook/types.go b/tools/archive/facebook/types.go index 85da0597..b25776b6 100644 --- a/tools/archive/facebook/types.go +++ b/tools/archive/facebook/types.go @@ -1,6 +1,10 @@ package main -import "time" +import ( + "time" + + "github.com/by-jp/www.byjp.me/tools/shared" +) type PostCheckinPhotoOrVideo struct { Title string `json:"title"` @@ -82,3 +86,55 @@ func (ds DataSlice) GetSubstrings(key string, sub string) []string { return substrs } + +func (ds DataSlice) GetLocation() (shared.Location, bool) { + for _, obj := range ds { + iface, ok := obj["place"] + if !ok { + continue + } + + p, ok := iface.(map[string]interface{}) + if !ok { + continue + } + + nameI, nameOK := p["name"] + if !nameOK { + continue + } + + name, ok := nameI.(string) + if !ok { + continue + } + + coordsI, coordsOK := p["coordinate"] + if !coordsOK { + continue + } + + coordsM, ok := coordsI.(map[string]interface{}) + if !ok { + continue + } + + lat, ok := coordsM["latitude"] + if !ok { + continue + } + + lng, ok := coordsM["longitude"] + if !ok { + continue + } + + return shared.Location{ + Name: name, + Latitude: lat.(float64), + Longitude: lng.(float64), + }, true + } + + return shared.Location{}, false +} diff --git a/tools/shared/types.go b/tools/shared/types.go index 53aeadf2..ace0fc06 100644 --- a/tools/shared/types.go +++ b/tools/shared/types.go @@ -15,6 +15,13 @@ type FrontMatter struct { RepostOf string `yaml:"repostOf,omitempty"` References []Reference `yaml:"references,omitempty"` Type string `yaml:"type,omitempty"` + Location Location `yaml:"location,omitempty"` +} + +type Location struct { + Name string `yaml:"name"` + Latitude float64 `yaml:"latitude"` + Longitude float64 `yaml:"longitude"` } type Reference struct {