我目前正在使用 Nikola 作为页面生成器。
但是根据页面范围和用户,Lektor 对最终用户来说似乎更容易和更精简。这非常适合我计划的新页面。
Nikola 还嵌入了媒体(youtube、vimeo、soundcloud 等) https://getnikola.com/handbook.html#restructuredtext-extensions
Lektor 如何提供这样的功能?
@A的答案。杰西是对的。由于保持核心的简单性Lektor
,就像Flask
自动嵌入不是由“核心”完成的。
然而,本着同样的精神,Flask
,Lektor
是高度可扩展的。这也适用于它MarkDown
在帖子中解析格式化文本并呈现最终的 HTML。
正如他已经说过的,您可以直接将 HTML 中的可嵌入代码粘贴到其他 MarkDown 文本中。并且,它将按原样包含在最终的 HTML 中。
但是,我个人认为这损害了 MarkDown 的简单性和快速可读性的核心意图。
易读易写的纯文本格式
这就是为什么我觉得有必要使用lektor-embed-x,作者将在单独的段落中写下内容的链接。这个小插件将在可能的范围内完成其余的工作。它基本上是embedX和Lektor
.
<a href=...
链接。用法很简单。
步骤 1 通过以下方式添加插件:
$ cd path/to/lektor/project_folder
$ lektor plugins add lektor-embed-x
Package lektor-embed-x (0.1.2) was added to the project
而已。你准备好了。【截至目前,暂无新增配置。】
现在,在帖子上,您可以在自己的段落中添加链接,无需任何特殊标记或开始标志,在您的MarkDown
格式化帖子中,如下所示。
title: About this Website
---
body:
This is a website that was made with the Lektor quickstart.
And it does not contain a lot of information.
# **HEADING 1**
## 2nd head
_italic slated text_
~~mess~~
whatever text i need to write.
https://twitter.com/codinghorror/status/686254714938200064
Below is how I can embed in a post.
http://www.youtube.com/watch?v=_lOT2p_FCvA
So, that was what i wanted to say.
通过 生成最终的 HTML 后Lektor
,上面的帖子将生成如下内容:
请注意,这是一个非常新生的单人项目,正在积极开发中,刚刚结束了 pre-alpha 阶段。因此,提供者或链接格式并不多。然而。但是,我希望它会在短时间内成熟。
Lektor 中还没有提供它。通常使用 Lektor,您可以在 Markdown 中编写内容。您可以简单地将 HTML 嵌入代码(来自 YouTube 或任何服务)直接粘贴到您的 Markdown 中。但是有一个刚刚发布的名为lektor-embed-x的插件可以做你想做的事。
如果您可以使用流,您当然也可以为您的媒体定义流块。这也允许通过管理员中显示的选项进行更多控制。例如,一个非常简单(无功能)的 youtube 流块可能如下所示:
流块/youtube.ini:
[block]
name = Youtube
button_label = Youtube Video
[fields.ytid]
label = Video ID
type = string
width = 1/2
模板/块/youtube.html:
<iframe width="560" height="315" src="https://www.youtube.com/embed/{{this.ytid}}" frameborder="0" allowfullscreen></iframe>
这定义了一个名为“Youtube Video”的新块类型,内部名称为“youtube”。用户必须输入 youtube 视频 id(视频 url 中 ?v= 之后的字母/数字),然后通过 this.ytid 参考在模板中使用。
使用这种技术,还可以添加更多选项。下面是一个几乎功能齐全的示例。
流块/youtube.ini:
[block]
name = Youtube
button_label = Youtube Video
[fields.ytid]
label = Video ID
type = string
width = 1/2
[fields.size]
label = Video size
type = select
choices = 560x315, 640x360, 853x480, 1280x720
choice_labels = 560 x 315, 640 x 360, 853 x 480, 1280 x 720
default = 560x315
width = 1/2
[fields.rel]
label = Show suggested videos when the video finishes
type = boolean
default = true
width = 1/4
[fields.controls]
label = Show player controls
type = boolean
default = true
width = 1/4
[fields.showinfo]
label = Show video title and player actions
type = boolean
default = true
width = 1/4
[fields.nocookie]
label = Enable privacy-enhanced mode
type = boolean
width = 1/4
模板/块/youtube.html:
<iframe width="{{ this.size.split("x")[0] }}" height="{{ this.size.split("x")[1] }}" src="https://www.youtube{{ "-nocookie" if this.nocookie }}.com/embed/{{this.ytid}}?{{ "rel=0&" if not this.rel}}{{ "controls=0&" if not this.controls }}{{ "showinfo=0" if not this.showinfo }}" frameborder="0" allowfullscreen></iframe>
也许可以使用一些智能正则表达式来允许用户粘贴完整的 youtube url,这样他们就不需要手动提取视频 id。但我还没有尝试过。