grav cms
I recently switched my blog over from Blogger to Grav, and while quite a nifty platform on its own, Grav really shines once you prop it up with some custom themes and plugins.
我最近将我的博客从Blogger切换到了Grav ,虽然它本身是一个非常漂亮的平台,但是当您使用一些自定义主题和插件对其进行支持时, Grav确实会发光。
This post will list the plugins I believe to be essential for a developer’s personal blog, and the reasons behind each suggestion.
这篇文章将列出我认为对开发人员的个人博客至关重要的插件,以及每个建议背后的原因。
It goes without saying that every Grav installation should have the Admin panel installed. It’s a fantastic addon that makes the software much more usable, allows you to install plugins easily, lets you handle localization and translation, and much more.
不用说,每个Grav安装都应该安装“管理”面板。 这是一个了不起的插件,它使该软件更加易用,可让您轻松安装插件,处理本地化和翻译等。
The installation instructions for the Admin panel are in the official docs.
管理面板的安装说明在官方文档中 。
Most themes have some kind of Google Analytics support baked-in, but some don’t, and some only have it on certain pages. If you’re not interested in extending a theme just to include a GA snippet in a template, the Google Analytics plugin is the right choice.
大多数主题有某种烤入谷歌Analytics(分析)的支持,但有的没有,有的只有它在某些页面。 如果您不希望扩展主题以仅在模板中包含GA代码段,则可以选择Google Analytics(分析)插件 。
Once installed, a configuration option will appear in the plugins interface and allow for insertion of the UA key, which will then be injected into every page – regardless of whether or not the chosen theme supports it out of the box.
安装后,配置选项将出现在插件界面中,并允许插入UA密钥,然后将其插入到每个页面中-不管所选主题是否开箱即用。
The archive plus plugin helps produce an archive tree of posts sorted by month and year, much like the archive links on Blogger.
加上归档文件的插件有助于生成按月和年排序的帖子的归档树,非常类似于Blogger上的归档链接。
*Note: To use this one, an extended theme is necessary, but that’s very easy to accomplish. See the Bonus tweaks section at the end of this list.
*注意:要使用此主题,需要扩展主题,但这很容易实现。 请参阅此列表末尾的“ 奖金调整”部分。
Once installed, from the root of the installation, we copy the archive partial from the plugin’s folder into our custom theme (modify folder names as per your own custom theme’s name):
安装完成后,从安装的根目录开始,将存档部分从插件的文件夹复制到我们的自定义主题(根据您自己的自定义主题的名称修改文件夹名称):
mkdir -p user/themes/cacti-swader/templates/partials cp user/plugins/archive_plus/templates/partials/archive_plus.html.twig user/themes/cacti-swader/templates/partials/archive_plus.html.twigThe archive plus partial can now be used in any other template as usual. For example, to include it in the home page of our custom Cacti theme, we copy the post-list template from the theme to our custom theme’s templates folder, and add the partial inclusion into the content block, like so:
现在可以像往常一样在任何其他模板中使用归档文件和部分文件。 例如,要将其包含在自定义Cacti主题的主页中,我们将主题post-list的post-list模板复制到自定义主题的templates文件夹,然后将部分包含项添加到content块中,如下所示:
{% block content %} {% include 'partials/archive_plus.html.twig' %}Note that for things to show up, they need to have some taxonomy applied. For example, give them the tag “blog” and then in the plugin’s settings under Filters select tag -> blog, otherwise, nothing will show up.
请注意,要显示事物,它们需要应用一些分类法。 例如,给他们加上标签 “ blog”,然后在插件的“过滤器”下,选择tag -> blog ,否则什么都不会显示。
Note: right now, the plugin doesn’t work well with multi-language sites in that it caches its archive tree once for the whole site, rather than per language. A fix is in progress.
注意:目前,该插件不适用于多语言站点,因为它为整个站点而不是每种语言缓存一次存档树。 正在进行修复。
The external links plugin adds a small “external link” icon to all links that lead away from the blog’s domain. Simple, and effective.
外部链接插件会向所有离开博客域的链接添加一个小的“外部链接”图标。 简单,有效。
Note: If you’re using a theme with the langswitcher functionality for multi-language support, like Cacti, the langswitcher partial forces a default external class in the language links. The most effective solution (besides upvoting the issue requesting a customizable class) is to extend the langswitcher’s partial by copying it into a custom theme.
注意:如果您正在使用具有langswitcher功能的主题以支持多语言,例如Cacti,则langswitcher部分会在语言链接中强制使用默认的external类。 最有效的解决方案(除了解决请求自定义类的问题之外)是通过将langswitcher的partial复制到自定义主题中来扩展它。
Medium-style indicator of estimated reading time for a given post is provided by the official reading time plugin.
官方阅读时间插件提供了给定帖子的预计阅读时间的中型指标。
Once installed, the plugin adds a new Twig filter which we can use on some text to turn it into a reading time label, like so:
安装后,该插件会添加一个新的Twig过滤器,我们可以在某些文本上使用该过滤器将其转换为阅读时间标签,如下所示:
{{ page.content|readingtime({'minutes_label': 'min', 'minute_label': 'min', 'seconds_label': 's', 'second_label': 's'}) }}This can then be placed anywhere in the post to show readers how much time they’ll have to set aside to read a post. Protip: it’s best to keep this under 10 minutes!
然后可以将其放置在帖子中的任何位置,以向读者显示他们需要留出多少时间阅读帖子。 提示:最好将其保持在10分钟以内!
Note also that you can change the labels to those of your choice – useful when localizing.
还请注意,您可以将标签更改为您选择的标签-在本地化时很有用。
The Sitemap plugin automatically builds a search-engine friendly sitemap. This works equally well on multi-language sites, but requires the lang prefix before the sitemap route to actually render the language’s sitemap:
Sitemap插件会自动构建对搜索引擎友好的Sitemap。 这在多语言站点上同样有效,但是在站点地图路由之前需要lang前缀才能实际呈现该语言的站点地图:
With this plugin, your site is immediately ready for submission to search engines.
使用此插件,您的网站可以立即准备提交给搜索引擎。
Every developer needs code highlights in their blog posts, and the highlight plugin is what does the trick.
每个开发人员都需要在其博客文章中突出显示代码,而突出显示插件正是解决之道。
After installing it, to use it one needs to either manually edit the front-matter of a page (the stuff that goes before the content), or use expert mode in the Admin UI to edit it there, and include a highlight theme declaration. My example in the image below uses the Monokai theme:
安装后,要使用它,需要手动编辑页面的前部内容(内容之前的内容),或在管理界面中使用专家模式在此处进行编辑,并包括突出显示主题声明。 下图中的示例使用了Monokai主题:
When rendered, it looks like this:
渲染后,它看起来像这样:
The following should be kept in mind:
请记住以下几点:
to minimize performance impact, it’s best to only activate highlights per every page which needs it.
为了最大程度地降低性能影响,最好仅在每个需要它的页面上激活突出显示。
the plugin will try to autodetect the language it needs to render if no language hints are provided, but it’s recommended to always provide them for both performance and accuracy:
如果未提供语言提示,则插件将尝试自动检测其需要呈现的语言,但是建议始终提供它们以提高性能和准确性:
```php <?php echo "Hello"; ```While we’re on the topic of performance, the Advanced Page Cache Plugin caches pages in full based on their URLs and uses these static versions in future requests.
当我们讨论性能问题时,“ 高级页面缓存插件”将根据页面的URL完全缓存页面,并在以后的请求中使用这些静态版本。
As the docs say, this means a manual cache bust is required when any changes are made, however, the performance improvements are rather dramatic and worth it. It’s important to keep the following in mind:
正如文档所说,这意味着在进行任何更改时都需要手动进行缓存清除,但是,性能的提高是非常显着的,值得这样做。 注意以下几点很重要:
This plugin is intended for production scenarios where optimal performance is desired and more important than convenience. AdvancedPageCache is not intended to be used in a development environment or a rapidly changing one.
该插件用于需要最佳性能且比便捷性更重要的生产场景。 AdvancedPageCache不适用于开发环境或快速变化的环境。
Many plugin events will not fire when a cached page is found becuase these are not processed by Grav, only the static page is returned. For example, because there is no RenderEvent with the cached page, the DebugBar will not show even if enabled.
当找到缓存的页面时,许多插件事件将不会触发,因为Grav不会处理这些事件,仅返回静态页面。 例如,由于缓存的页面没有RenderEvent,因此即使启用DebugBar也不会显示。
Also keep in mind that the plugin doesn’t really work as well as it should with multi-language sites, so it’s best to use it only in production and only on single-language sites. For powerful multi-language site caching, look into a front layer like Varnish.
另外请记住,该插件在多语言站点上的工作效果并不理想,因此最好仅在生产环境中和仅在单语言站点上使用它。 要获得强大的多语言站点缓存,请查看Varnish之类的前层。
As a developer, you might sometimes need to draw diagrams in your explanations of the code you’re presenting. The diagrams plugin helps with that.
作为开发人员,您有时可能需要在所提供代码的说明中绘制图表 。 图表插件可以帮助您。
This plugin allows you to define diagrams within the Markdown content of your post(s), thus bypassing the need to any sort of illustration software, and keeping the style consistent across all your writings. Here are examples of two diagrams produced with the plugin – for actual usage, please see the plugin’s README file.
该插件使您可以在帖子的Markdown内容中定义图表,从而无需使用任何种类的插图软件,并在所有作品中保持样式一致。 以下是该插件产生的两个图表的示例–有关实际用法,请参阅该插件的README文件。
Here are some bonus tweaks you should apply to your Grav installation.
这是一些您应该应用于Grav安装的奖金调整。
When ever something new is installed, remember to clear the cache (from the Dashboard) to apply changes.
一旦安装了新的东西,切记要清除缓存(从仪表板中)以应用更改。
In the case of, for example, the reading plugin above, you might want to prefix the time with a “Reading time:” label. However, this can get awkward when using a theme with multi-language functionality built in, like the Cacti theme I’m using.
例如,对于上面的阅读插件,您可能需要在时间前加上“阅读时间:”标签。 但是,当使用带有内置多语言功能的主题(例如我正在使用的Cacti主题)时,这样做可能会很尴尬。
To help with this, each multi-language supporting theme has a languages.yaml file in its root folder. Here’s an example from my own modified Cacti language file:
为了解决这个问题,每个支持多种语言的主题在其根文件夹中都有一个languages.yaml文件。 这是我自己修改后的Cacti语言文件中的示例:
en: SITE: TITLE: Bitfalls.com DESCRIPTION: Developer, Complainer, Beagle Owner COPYRIGHT: © Copyright %s Bitfalls.com SUBSCRIBE: RSS TWEET: Tweet SHARE: Share MONTHS_OF_THE_YEAR: [January, February, March, April, May, June, July, August, September, October, November, December] DAYS_OF_THE_WEEK: [Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday] READING_TIME: Reading time hr: SITE: TITLE: Bitfalls.com DESCRIPTION: Programer, bundžija, vlasnik bigla COPYRIGHT: © Prava: %s Bitfalls.com MONTHS_OF_THE_YEAR: [Sijecanj, Veljaca, Ozujak, Travanj, Svibanj, Lipanj, Srpanj, Kolovoz, Rujan, Listopad, Studeni, Prosinac] DAYS_OF_THE_WEEK: [Ponedjeljak, Utorak, Srijeda, Cetvrtak, Petak, Subota, Nedjelja] READING_TIME: Vrijeme čitanjaThe values that aren’t defined in the secondary language (and others) default back to those from the primary one. Notice the label READING_TIME. To use it in a template, we do this:
未在次要语言(和其他语言)中定义的值将默认回到主要语言中的值。 注意标签READING_TIME 。 要在模板中使用它,我们可以这样做:
{{ "READING_TIME"|t }}The t filter to which we’re piping the string is a translate filter which looks at the language.yaml file of the theme and pulls the value from there:
我们将字符串传递到的t过滤器是一个转换过滤器,它查看主题的language.yaml文件并从那里获取值:
In case of arrays, like with dates above, the ta filter comes in handy:
对于数组,例如上面的日期, ta过滤器很方便:
'MONTHS_OF_THE_YEAR'|ta(page.date|date('n') - 1)The above snippet means “send the array MONTHS_OF_THE_YEAR to the ta (translateArray) filter, and translate its X element, where X is page.date|date('n') - 1“.
上面的代码段表示“将数组MONTHS_OF_THE_YEAR发送到ta (translateArray)过滤器,并转换其X元素,其中X为page.date|date('n') - 1 ”。
Extending a theme is relatively easy, and should be done to allow for inclusion of custom partials and edited templates without breaking the parent theme. This also allows us to update the theme via the official channels. To extend a theme (the example uses the Cacti theme):
扩展主题相对容易 ,并且应做到在不破坏父主题的情况下允许包含自定义部分和已编辑的模板。 这也使我们可以通过官方渠道更新主题。 扩展主题(示例使用Cacti theme ):
Create a new folder in user/themes. E.g. user/themes/cacti-swader.
在user/themes创建一个新文件夹。 例如user/themes/cacti-swader 。
Create a new YAML file: user/themes/cacti-swader/cacti-swader.yaml:
创建一个新的YAML文件: user/themes/cacti-swader/cacti-swader.yaml :
streams: schemes: theme: type: ReadOnlyStream prefixes: '': - user/themes/cacti-swader - user/themes/cactiRemember to include any additional values into this same file that already exist in the default user/themes/cacti/cacti.yaml, otherwise, some theme functionality might be missing:
请记住,将默认user/themes/cacti/cacti.yaml中已经存在的所有其他值都包含到该文件中,否则,可能会缺少某些主题功能:
enabled: true author: Bruno Škvorc title_header: false home_profile: true infinite_scroll: true analytics: UA-xxxxxxxx-1 social: twitter: @bitfallsCreate a /user/themes/cacti-swader/blueprints.yaml file:
创建一个/user/themes/cacti-swader/blueprints.yaml文件:
name: Cacti Swader version: 1.0.0 description: "Extending Cacti" icon: crosshairs author: name: Bruno Skvorc email: bruno.skvorc@sitepoint.com url: http://bitfalls.comModify the theme value under pages in /user/config/system.yaml to be cacti-swader.
将/user/config/system.yaml pages下的theme值修改为cacti-swader 。
That’s it. The extended theme will be read first, and anything missing will be pulled from the base theme. For more advanced theme extension procedures, this post will come in handy.
而已。 扩展主题将首先被阅读,所有遗漏的内容将从基础主题中提取。 有关更高级的主题扩展程序, 本帖子将派上用场。
Grav is a relatively new, highly performant, and very intuitive flat-file CMS which, while not being very anal on security, is highly dedicated to simplicity and usability.
Grav是一个相对较新的,高性能的,非常直观的平面文件CMS,尽管它在安全性方面不是很强,但是却非常注重简单性和可用性。
In a future post, I’ll cover some advanced plugins for implementing comments, image auto-optimization, CDNs, and much more.
在以后的文章中,我将介绍一些用于实现注释,图像自动优化,CDN等的高级插件。
I’ll also talk more about why I picked Grav in a later post, but for now I’d like to know what you are using for a personal blogging engine (Static site generators? Full blown CMS?), and whether or not you’d like to recommend some Grav plugins I missed.
我还将在以后的文章中进一步讨论为什么选择Grav,但是现在我想知道您使用的个人博客引擎(静态网站生成器?全面的CMS?),以及是否想推荐一些我错过的Grav插件。
Let us know!
让我们知道!
翻译自: https://www.sitepoint.com/8-must-have-grav-plugins-to-round-off-your-blogs-installation/
grav cms
相关资源:Grav一个快速简单灵活基于文件的CMS