mirror of
https://github.com/by-jp/www.byjp.me.git
synced 2025-08-09 18:06:07 +01:00
Fix multiple images
This commit is contained in:
parent
3297f5c35d
commit
9f8c504395
3 changed files with 20 additions and 12 deletions
|
@ -72,7 +72,7 @@ type tweet struct {
|
|||
MediaURL string `json:"media_url"`
|
||||
ExpandedURL string `json:"expanded_url"`
|
||||
}
|
||||
} `json:"entities"`
|
||||
} `json:"extended_entities"`
|
||||
} `json:"tweet"`
|
||||
}
|
||||
|
||||
|
@ -212,7 +212,7 @@ func tweetToNote(t tweet, mediaMap map[string]string, outputDir string, selfUser
|
|||
fm.Tags = append(fm.Tags, tag)
|
||||
return fmt.Sprintf("%s{{< friend \"%s\" >}}", before, name)
|
||||
} else if prefix == "@" {
|
||||
return fmt.Sprintf("%s[@%s](https://twitter.com/%s)", before, label, label)
|
||||
return fmt.Sprintf("%s[@%s](/twitter/#/%s)", before, label, label)
|
||||
} else if prefix == "#" {
|
||||
fm.Tags = append(fm.Tags, label)
|
||||
return fmt.Sprintf("%s[%s](/tags/%s)", before, label, label)
|
||||
|
@ -224,19 +224,24 @@ func tweetToNote(t tweet, mediaMap map[string]string, outputDir string, selfUser
|
|||
// Add media
|
||||
mp := getMediaPaths(t)
|
||||
i := 1
|
||||
for twitURL, zipPath := range mp {
|
||||
ext := path.Ext(zipPath)
|
||||
hugoName := fmt.Sprintf("media-%d%s", i, ext)
|
||||
hugoMedia := path.Join(postDir, hugoName)
|
||||
for twitURL, zipPaths := range mp {
|
||||
var newImages string
|
||||
|
||||
for _, zipPath := range zipPaths {
|
||||
ext := path.Ext(zipPath)
|
||||
hugoName := fmt.Sprintf("media-%d%s", i, ext)
|
||||
newImages = fmt.Sprintf(`%s%s{{< imgorvid src="%s" >}}`, newImages, "\n", hugoName)
|
||||
|
||||
mediaMap[zipPath] = path.Join(postDir, hugoName)
|
||||
i++
|
||||
}
|
||||
|
||||
mediaMap[zipPath] = hugoMedia
|
||||
text = strings.Replace(
|
||||
text,
|
||||
fmt.Sprintf("[%s](%s)", twitURL, twitURL),
|
||||
fmt.Sprintf(`{{< imgorvid src="%s" >}}`, hugoName),
|
||||
newImages,
|
||||
1,
|
||||
)
|
||||
i++
|
||||
}
|
||||
|
||||
// Add date
|
||||
|
@ -411,8 +416,9 @@ func untwitpic(url string, postDir string) (string, error) {
|
|||
return fName, nil
|
||||
}
|
||||
|
||||
func getMediaPaths(t tweet) map[string]string {
|
||||
paths := make(map[string]string)
|
||||
func getMediaPaths(t tweet) map[string][]string {
|
||||
paths := make(map[string][]string)
|
||||
|
||||
for _, m := range t.Tweet.Entities.Media {
|
||||
partName := path.Base(m.MediaURL)
|
||||
if strings.Contains(m.MediaURL, "/tweet_video_thumb/") {
|
||||
|
@ -420,7 +426,8 @@ func getMediaPaths(t tweet) map[string]string {
|
|||
}
|
||||
fname := fmt.Sprintf("%s-%s", t.Tweet.ID, partName)
|
||||
|
||||
paths[m.ExpandedURL] = path.Join("data", "tweets_media", fname)
|
||||
imgPath := path.Join("data", "tweets_media", fname)
|
||||
paths[m.ExpandedURL] = append([]string{imgPath}, paths[m.ExpandedURL]...)
|
||||
}
|
||||
return paths
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=
|
||||
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
|
||||
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
|
||||
|
|
Loading…
Reference in a new issue