Enable Jekyll's LSI for related posts with fast build speed

Enable Jekyll's LSI for related posts with fast build speed

boost build speed with gsl

Web Notes / Tutorials

2019.11.21

12 👣 #jekyll #lsi #gsl

Jekyll’s site.related_posts by default just presents 10 recent posts. If you set the lsi to true in _config.yml, the related_posts can really work as it describes. However, enable lsi will certainly slow down the building speed. Especially for posts that written in Chinese, seems like the latent semantic indexing (LSI) will never stop and the Jekyll build process will last for hours and hours…

So, I end up with a manually programmed related posts by targetting the posts with the same tag/category using pure Liquid in Jekyll’s templates. Details can be found in my old post: Related posts in Jekyll.

What is LSI?

Why enable lsi will lead to such slow build speed? We need to have a general feeling on what is the LSI - latent sematic indexing.

LSI, sometimes referred as latent semantic analysis, is a mathematical method developed in the late 1980s to improve the accuracy of information retrieval. It uses a technique called singular value decomposition to scan unstructured data within documents and identify relationships between the concepts contained therein.

In essence, it finds the latent relationships between words (semantics) in order to improve information understanding (indexing). It provided a significant step forward for the field of text comprehension as it accounted for the contextual nature of language.

So, it needs additional calculations among different posts for finding the related posts.

Speed up LSI

It’s great to have lsi enabled for accurate related posts, and things become easier with rb-gsl that speed up LSI immensely.

However, rb-gsl requires gsl (GNU Scientific Library) as the runtime dependency, you need to install gsl locally on your build environment.

On macOS, that’s easy with Homebrew:

brew install gsl

On Ubuntu/Debian:

sudo apt-get -y install libgsl-dev

Then, install these two gems or add them to your Gemfile then install them with bundler:

gem install classifier-reborn
gem install gsl

Now, you can safely enable lsi to build related posts with super fast speed.

In case you’re testing your site that doesn’t care about the related posts, you can set lsi to false in _config.yml and build related posts to only in production environment with bundle exec jekyll build --lsi.

Note that GitHub Pages doesn’t support lsi… But, Netlify has already added gsl in their building image 👍.

THE END
Ads by Google

林宏

Frank Lin

Hey, there! This is Frank Lin (@flinhong), one of the 1.41 billion . This 'inDev. Journal' site holds the exploration of my quirky thoughts and random adventures through life. Hope you enjoy reading and perusing my posts.

YOU MAY ALSO LIKE

Related posts in Jekyll using pure Liquid

Web Notes

2016.07.13

Related posts in Jekyll using pure Liquid

Jekyll features a simple “Related posts” variable per post page with "site.related_posts", which just contains the 10 most recent posts by default. It only works perfectly when LSI (latent semantic indexing) option was enabled (slow building speed). The Liquid tags might be helpful here.

Using Liquid in Jekyll - Live with Demos

Web Notes

2016.08.20

Using Liquid in Jekyll - Live with Demos

Liquid is a simple template language that Jekyll uses to process pages for your site. With Liquid you can output complex contents without additional plugins.

Hands on IBM Cloud Functions with CLI

Tools

2020.10.20

Hands on IBM Cloud Functions with CLI

IBM Cloud CLI allows complete management of the Cloud Functions system. You can use the Cloud Functions CLI plugin-in to manage your code snippets in actions, create triggers, and rules to enable your actions to respond to events, and bundle actions into packages.

logout

长恨歌

白居易「唐代」

汉皇重色思倾国,御宇多年求不得。

杨家有女初长成,养在深闺人未识。

天生丽质难自弃,一朝选在君王侧。

回眸一笑百媚生,六宫粉黛无颜色。

春寒赐浴华清池,温泉水滑洗凝脂。

侍儿扶起娇无力,始是新承恩泽时。

云鬓花颜金步摇,芙蓉帐暖度春宵。

春宵苦短日高起,从此君王不早朝。

承欢侍宴无闲暇,春从春游夜专夜。

后宫佳丽三千人,三千宠爱在一身。

金屋妆成娇侍夜,玉楼宴罢醉和春。

姊妹弟兄皆列土,可怜光彩生门户。

遂令天下父母心,不重生男重生女。

骊宫高处入青云,仙乐风飘处处闻。

缓歌慢舞凝丝竹,尽日君王看不足。

渔阳鼙鼓动地来,惊破霓裳羽衣曲。

九重城阙烟尘生,千乘万骑西南行。

翠华摇摇行复止,西出都门百余里。

六军不发无奈何,宛转蛾眉马前死。

花钿委地无人收,翠翘金雀玉搔头。

君王掩面救不得,回看血泪相和流。

黄埃散漫风萧索,云栈萦纡登剑阁。

峨嵋山下少人行,旌旗无光日色薄。

蜀江水碧蜀山青,圣主朝朝暮暮情。

行宫见月伤心色,夜雨闻铃肠断声。

天旋地转回龙驭,到此踌躇不能去。

马嵬坡下泥土中,不见玉颜空死处。

君臣相顾尽沾衣,东望都门信马归。

归来池苑皆依旧,太液芙蓉未央柳。

芙蓉如面柳如眉,对此如何不泪垂。

春风桃李花开日,秋雨梧桐叶落时。

西宫南内多秋草,落叶满阶红不扫。

梨园弟子白发新,椒房阿监青娥老。

夕殿萤飞思悄然,孤灯挑尽未成眠。

迟迟钟鼓初长夜,耿耿星河欲曙天。

鸳鸯瓦冷霜华重,翡翠衾寒谁与共。

悠悠生死别经年,魂魄不曾来入梦。

临邛道士鸿都客,能以精诚致魂魄。

为感君王辗转思,遂教方士殷勤觅。

排空驭气奔如电,升天入地求之遍。

上穷碧落下黄泉,两处茫茫皆不见。

忽闻海上有仙山,山在虚无缥渺间。

楼阁玲珑五云起,其中绰约多仙子。

中有一人字太真,雪肤花貌参差是。

金阙西厢叩玉扃,转教小玉报双成。

闻道汉家天子使,九华帐里梦魂惊。

揽衣推枕起徘徊,珠箔银屏迤逦开。

云鬓半偏新睡觉,花冠不整下堂来。

风吹仙袂飘飘举,犹似霓裳羽衣舞。

玉容寂寞泪阑干,梨花一枝春带雨。

含情凝睇谢君王,一别音容两渺茫。

昭阳殿里恩爱绝,蓬莱宫中日月长。

回头下望人寰处,不见长安见尘雾。

惟将旧物表深情,钿合金钗寄将去。

钗留一股合一扇,钗擘黄金合分钿。

但教心似金钿坚,天上人间会相见。

临别殷勤重寄词,词中有誓两心知。

七月七日长生殿,夜半无人私语时。

在天愿作比翼鸟,在地愿为连理枝。

天长地久有时尽,此恨绵绵无绝期。