Demonstration of Jekyll Export from Mathematica
[metablogging
]
Our goal here is to demonstrate how to Export Mathematica notebooks to Jekyll markdown using MDExport. This requires a bit of custom code, demonstrated below, which we’ll use to define a function that automates the process.
But first, a simple illustration of plotting Maxwell-Boltzmann distribution
mb[kT_, m_, u_] := 4 Pi ( m/(2 kT Pi ))^{3/2} u^2 Exp[-m u^2/(2 kT)]
Plot[
{mb[1, 1, u], mb[2, 1, u], mb[1, 2, u]}, {u, 0, 8},
PlotStyle -> {Black, Red, Red},
Frame -> True, FrameTicks -> None,
PlotLegends -> Placed[{"\[UpArrow]m", "\[UpArrow]T"}, {Right, Top}],FrameLabel -> {"Velocity", "Probability Density"},
ImageSize -> Small]
Clear[ToJekyll]
ToJekyll[title_, tags_ : "", blogLocation_ : "~/Documents/GitHub/blog"] := With[
{blogFile = StringJoin[
DateString["ISODate"], "-", StringReplace[title, " " -> "-"], ".md"],
imageLocation = FileNameJoin[{"/images"}~Join~Map[ToString, DateList[][[;; 3]]]]
},
CreateDirectory[imageLocation] // Quiet;
With[
{mdFile =
M2MD[
EvaluationNotebook[],
"ImagesExportURL" -> FileNameJoin[{blogLocation, imageLocation}],
"ImagesFetchURL" -> URL[FileNameJoin[{"/blog", imageLocation}]]],
titleStr = StringJoin["---\ntitle: \"", title, "\""],
dateStr = StringJoin["date: ", DateString["ISODate"]],
tagStr = StringJoin["tags: ", tags, "\n---\n"],
outputFile = OpenWrite[FileNameJoin[{blogLocation, "_posts", blogFile}]]},
WriteLine[outputFile, titleStr];
WriteLine[outputFile, dateStr];
WriteLine[outputFile, tagStr];
WriteLine[outputFile, mdFile];
Close[outputFile];
]]
DefineResourceFunction[ToJekyll] (*define for later use*)
ToJekyll["Demonstration of Jekyll Export from Mathematica", "metablogging"]