Changed IDs to be Unix Timestamps of First Publishing Date

Christopher Vollick [2010-03-20 18:56]
Changed IDs to be Unix Timestamps of First Publishing Date

This was suggested by Stephen.
I was initially resistent to this.

I've changed my mind.

The reason is because it turns out it's much easier to deal with renamed files this way.

I would have had to do some heuristic hacks to detect when a file disappeared and was readded.
In this case, I just deal with the articles that exist, and use the --follow flag to log to track it through renames.

Yeah yeah, the data's more semantic too.
Filename
gitsite
diff --git a/gitsite b/gitsite
index 1f85dbf..6203f22 100755
--- a/gitsite
+++ b/gitsite
@@ -35,49 +35,50 @@ tmpArticleTemplateDir="$tmpDir/articleTemplated"
 mkdir -p "$tmpArticleTemplateDir"

 # Get the list, in order of creation, of all articles
-articles="$(git whatchanged --pretty=format: articles/ | sed -n '/A	/s/.*A	\(.*\)/\1/p' | tail -r)"
+articlesAndIds="$(ls articles/ | while read article; do echo "$(git log --follow --pretty=format:%at "articles/$article" | sed -n '$p')	$article"; done | sort)"
+
+ids="$(echo "$articlesAndIds" | cut -d '	' -f1)"
+articles="$(echo "$articlesAndIds" | cut -d '	' -f2)"

 # Get the number of articles (Also the max ID)
 numArticles="$(echo "$articles" | wc -l)"

-for ID in $(seq 1 $numArticles); do
-
-	if [ '!' -e "articles/$title" ]; then
-		# Deleted at some point.
-		# Not expecting this to come up, but just in case, skip it.
-		continue
-	fi
+for index in $(seq 1 $numArticles); do

 	# Find the surrounding articles
-	prev="$(echo "$articles" | sed -n "$(expr $ID - 1)p")"
-	next="$(echo "$articles" | sed -n "$(expr $ID + 1)p")"
+	prev="$(echo "$articles" | sed -n "$(expr $index - 1)p")"
+	next="$(echo "$articles" | sed -n "$(expr $index + 1)p")"

 	# Get the title
-	title="$(basename "$(echo "$articles" | sed -n "${ID}p")")"
+	title="$(echo "$articles" | sed -n "${index}p")"
+
+	# And the ID
+	id="$(echo "$ids" | sed -n "${index}p")"

 	# Get the encoded title
 	encTitle="$(echo "$title" | ./encode_filename)"

 	# Find all modification dates
-	dates="$(git log --pretty=format:%at "articles/$title")"
+	dates="$(git log --follow --pretty=format:%at "articles/$title")"

 	# Last Modification Date
 	modified="$(echo "$dates" | sed -n '1p')"

 	# Original Publishing Date
+	# This should be the same as the ID now, but might as well pull it from this source while I've got it
 	published="$(echo "$dates" | sed -n '$p')"

 	# Run the article through the markup engine
 	./markup_engine < "articles/$title" > "$tmpArticleDir/$title"

 	# Now, run the article template on the content.
-	templates/article Content "|$tmpArticleDir/$title" Title "$title" Next "$next" Previous "$prev" CreationDate "$published" ModificationDate "$modified" ID "$ID" > "$tmpArticleTemplateDir/$title"
+	templates/article Content "|$tmpArticleDir/$title" Title "$title" Next "$next" Previous "$prev" CreationDate "$published" ModificationDate "$modified" ID "$id" > "$tmpArticleTemplateDir/$title"

 	# Finish off with the site template
-	templates/site Content "|$tmpArticleTemplateDir/$title" Title "$title" Next "$next" Previous "$prev" CreationDate "$published" ModificationDate "$modified" ID "$ID" > "$articleDestDir/${encTitle}"
+	templates/site Content "|$tmpArticleTemplateDir/$title" Title "$title" Next "$next" Previous "$prev" CreationDate "$published" ModificationDate "$modified" ID "$id" > "$articleDestDir/${encTitle}"

 	# And make a permalink
-	ln -f "$articleDestDir/$encTitle" "$idDestDir/$ID"
+	ln -f "$articleDestDir/$encTitle" "$idDestDir/$id"
 done

 rm -rf "$tmpDir"
ViewGit