This was a somewhat quick project for this sunday.
With the App 4K stogram I downloaded all my photos from instagram. The program saves each file with time and date in the filename. So I placed each one of them in a folder, changing spaces to underscores in the filenames and ran the small script bellow to magically create the posts. I saved my files in content/instagram, keep that in mind if you use the script.
I tried this idea on my own site and have some detail questions
what are you doing with mp3 files (for instagram videos). I assume it’s as easy as adding mp3 to the extension in the script, but in the end depending on the ending the content of the md-file needs to be different.
is there any reason (performance?) to put them in a subdirectory per image? In my understanding of hugo it would also work with imagename.md in one folder if I have not hundreds of images?
I rewrote the script a little bit (to take care of the underscoring and moving the files into their own respective folders. Result below (careful in the end, I did not get the line endings correct, believe three lines are one):
#!/bin/bash
# replacing spaces with underscores
for file in *; do mv "$file" `echo $file | tr ' ' '_'` ; done
# creating subfolders and moving files
for x in ./*.jpg; do
mkdir "${x%.*}" && mv "$x" "${x%.*}"
done
# creating index.md for each subfolder
for dir in *;
do date=`cut -d'_' -f 1 <<< "$dir"`;
file=$dir'.jpg';
time=`cut -d'_' -f 2 <<< "$dir" | sed -e 's/\./\:/g'`;
datetime=$date'T'$time'+00:00';
printf '%s\n' '---' 'categories: ["instagram"]' "date: $datetime" 'description: ""' 'draft: false'
"featured_image: /instagram/$dir/$file" 'layout: post' 'slug:' 'stories:' 'subtitle:' 'title: Untitled' '---' '' "<img
src=\"$file\" />" > $dir/index.md ;
done
I am not extracting videos or mp3 files at all, as in my use case they are very rare.
No reason other than my own organisation, a side effect was that that this approach helps if you want to use the recent function .Resources in your template.
There are also some params that most people won’t need: stories, subtitle, and description.