Embedded Javascript Templating

Just a quick sample of an alternative to markdown in Hexo

Posted by Rodney Hartzell on 2021-02-21
Estimated Reading Time 3 Minutes
Words 592 In Total
Viewed Times

Hexo and EJS

Today I am taking another detour into the world of Hexo. Hexo is a blogging platform that is almost 100% command line driven. With Hexo the options for a blog "post" are markdown (.md) or embedded javascript (.ejs). Until recently I had never heard of ejs. So I figured that maybe I'd take a little time today and dive a little deeper. The following notes are all I have so far.

EJS is javascript based templating.

Here's an example

1
2
3
4
5
<% var random=" " .repeat(198).split("").map(x=> Math.random());
%>
<% random.forEach((c, i)=> {
%> <%=c.toFixed(10) + ((i + 1) % 6===0 ? "\n" : "" ) %>
<%});%>

Let's see some random numbers

0.1953300083 0.3513590117 0.7540332944 0.6487660728 0.8232033020 0.9348866639 0.6931811016 0.9777797656 0.6702882500 0.9134984128 0.1761289734 0.9039506467 0.0349380011 0.8559181942 0.3930614522 0.2534654411 0.5539840247 0.8478477684 0.6309166354 0.3427918581 0.4485075164 0.4633531129 0.9988381843 0.1172469164 0.9677495868 0.7908439854 0.2710018840 0.7000204715 0.7852794329 0.0971202889 0.7477609444 0.3273276485 0.6388875324 0.8721859091 0.5301794057 0.4949776032 0.8570590107 0.9278742591 0.1036222104 0.0620110503 0.0093270581 0.3249890349 0.1392380710 0.1624816328 0.5520436206 0.2171629909 0.2667391986 0.8528512426 0.4599688777 0.2302352945 0.8589246218 0.1270887272 0.5639478551 0.9755132907 0.2363903791 0.1768951543 0.2618930719 0.8134738202 0.2974549404 0.5854046971 0.0171518045 0.4511436265 0.1421191333 0.6051714785 0.3057862704 0.2702885011 0.6988649078 0.5483866169 0.1758258666 0.3290342887 0.4601957010 0.4621504073 0.4752089361 0.3763890992 0.7014533635 0.8144803629 0.1780274090 0.9999318562 0.1945559538 0.2340962360 0.2443300242 0.6733495387 0.5500568876 0.3692616792 0.1009518733 0.0344561544 0.0569817870 0.9253102809 0.6200648875 0.9961130870 0.8016267527 0.7678580252 0.8630278884 0.2645417663 0.0118202444 0.6231628790 0.7181886022 0.0467580617 0.3617817185 0.2093572462 0.3351410060 0.0118647943 0.0953127829 0.7035150043 0.4318488921 0.6959111667 0.4748524668 0.3725703178 0.5785110377 0.5712061492 0.4484757803 0.5117570605 0.4786954654 0.5895638033 0.8362390384 0.9761605245 0.5770215931 0.3836268473 0.4561926881 0.0150241532 0.8737261808 0.4833632281 0.8130396268 0.4203107384 0.7607136781 0.2129034569 0.4595175991 0.6639200973 0.3980758413 0.1170828795 0.5154853099 0.2570755626 0.1356203755 0.5744639768 0.6504041834 0.7578145963 0.3402378867 0.6637993061 0.3807079839 0.0613219603 0.4950991924 0.7768718770 0.1238975040 0.8482688064 0.2391363968 0.4946540394 0.5309539624 0.1067712106 0.7505269177 0.9447531918 0.7636991190 0.8336247196 0.8967684886 0.2343553123 0.1436829296 0.8656021127 0.7951760058 0.2500725014 0.5589741388 0.2187878030 0.8168572969 0.9465850922 0.5943025247 0.8507994353 0.9070475013 0.3556754228 0.9521079677 0.5546220684 0.9766152360 0.3454109367 0.0043487121 0.5119719697 0.5970394514 0.7722245083 0.5210793862 0.0604815116 0.3210334438 0.7441317310 0.4171628951 0.6438163645 0.4669464647 0.2088189326 0.7921787758 0.7401118615 0.1124989215 0.1867246272 0.9225535292 0.8278781295 0.2138177513 0.0318100586 0.9633042662 0.6684341742 0.5003080104 0.1931820687 0.1152910522 0.1709202225 0.5960845440 0.8131357896

And just like that, you have a page full of numbers.

Let's try some HTML

Drag the mouse on the graph to rotate the image. Use the scrollwheel to zoom in and out.

Well, there ya go! Not too shabby. This is a blog post with a mix of Hexo layout meta-data, embedded javascript templating and HTML


If you like this blog or find it useful for you, you are welcome to comment on it. You are also welcome to share this blog, so that more people can participate in it. If the images used in the blog infringe your copyright, please contact the author to delete them. Thank you !