mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-21 02:10:11 +08:00
commit
fc47abd312
@ -1,79 +0,0 @@
|
||||
[#]: subject: "Reveal your source code with Jinja2 and Git"
|
||||
[#]: via: "https://opensource.com/article/21/12/reveal-source-code-jinja2-git"
|
||||
[#]: author: "Ayush Sharma https://opensource.com/users/ayushsharma"
|
||||
[#]: collector: "lujun9972"
|
||||
[#]: translator: "geekpi"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
Reveal your source code with Jinja2 and Git
|
||||
======
|
||||
Here's how I keep my website open by linking every page back to its
|
||||
original source.
|
||||
![Text editor on a browser, in blue][1]
|
||||
|
||||
I'm a huge fan of open source.
|
||||
|
||||
One of the little ways I've supported the cause is by keeping my personal blog site open from the very beginning. I do this partly to let people see the history of changes behind each page. But I also do it because, when I started using [Jekyll][2], I didn't find many open source Jekyll blogs to learn from. My hope is that keeping my website open and exposing my trials and errors will save someone else a lot of time.
|
||||
|
||||
### The Jekyll page.path variable
|
||||
|
||||
One way I achieve that is by linking every entry I post back to its original [Markdown][3]. [Jekyll's helpful variables][4] have exactly the tool that's needed: the `page.path`. This variable contains the raw filesystem path of each page. The official description even highlights its usefulness for linking back to the source!
|
||||
|
||||
Printing `{{ page.path }}` within an article's Markdown file outputs something similar to this:
|
||||
|
||||
|
||||
```
|
||||
`_posts/2021-10-10-example.md`
|
||||
```
|
||||
|
||||
Assume that the article's source code existed at this path:
|
||||
|
||||
|
||||
```
|
||||
`https://example.com/ayushsharma-in/-/blob/master/_posts/2021-10-10-example.md`
|
||||
```
|
||||
|
||||
If you prepend `https://example.com/ayushsharma-in/-/blob/master/` to any article's `page.path`, it generates a link back to its source code.
|
||||
|
||||
In Jekyll, generating this full link looks like this:
|
||||
|
||||
|
||||
```
|
||||
`<a href="{{ page.path | prepend: site.content.blog_source_prefix }}" target="_blank">View source</a>`
|
||||
```
|
||||
|
||||
It's that easy.
|
||||
|
||||
### Jekyll and the open web
|
||||
|
||||
The modern web is an intricate and multilayered technology, but that doesn't mean it has to obfuscate. With Jekyll's variables, you ensure that your users can, if they wish, learn more about how you built your site.
|
||||
|
||||
You can see real-world examples on my [personal blog][5]: scroll to the bottom for the View Source link.
|
||||
|
||||
* * *
|
||||
|
||||
This article is adapted from [ayush sharma's notes][6] and is republished with permission.
|
||||
|
||||
See how Jekyll, an open source generator of static HTML files, makes running a blog as easy as...
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/21/12/reveal-source-code-jinja2-git
|
||||
|
||||
作者:[Ayush Sharma][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/ayushsharma
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/browser_blue_text_editor_web.png?itok=lcf-m6N7 (Text editor on a browser, in blue)
|
||||
[2]: https://opensource.com/article/21/9/build-website-jekyll
|
||||
[3]: https://opensource.com/article/19/9/introduction-markdown
|
||||
[4]: https://jekyllrb.com/docs/variables/#page-variables
|
||||
[5]: https://www.ayushsharma.in
|
||||
[6]: https://www.ayushsharma.in/2021/11/linking-jekyll-pages-back-to-their-git-source-code
|
@ -0,0 +1,76 @@
|
||||
[#]: subject: "Reveal your source code with Jinja2 and Git"
|
||||
[#]: via: "https://opensource.com/article/21/12/reveal-source-code-jinja2-git"
|
||||
[#]: author: "Ayush Sharma https://opensource.com/users/ayushsharma"
|
||||
[#]: collector: "lujun9972"
|
||||
[#]: translator: "geekpi"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
用 Jinja2 和 Git 公开你的源码
|
||||
======
|
||||
这里是我如何通过链接每个页面回到其原始来源来保持我的网站开放的方法,
|
||||
![Text editor on a browser, in blue][1]
|
||||
|
||||
我是一个开源的超级粉丝。
|
||||
|
||||
我支持这项事业的一个小方法是从一开始就保持我的个人博客网站开放。我这样做的部分原因是让人们看到每个页面背后的变化历史。还因为当我开始使用 [Jekyll][2] 时,我没有找到很多开源的 Jekyll 博客可以学习。我希望保持我的网站开放并公开我的尝试和错误会为其他人节省很多时间。
|
||||
|
||||
### Jekyll 的 page.path 变量
|
||||
|
||||
我实现这一目标的方法之一是将我发布的每一个条目链接到其原始的 [Markdown][3]。[Jekyll 的有用变量][4]正好有一个需要的工具:`page.path`。这个变量包含每个页面的原始文件系统路径。官方的描述甚至强调了它对链接回源的作用!
|
||||
|
||||
在一篇文章的 Markdown 文件中打印 `{{page.path }}`,可以得到类似这样的结果:
|
||||
|
||||
|
||||
```
|
||||
`_posts/2021-10-10-example.md`
|
||||
```
|
||||
|
||||
假设该文章的源代码存在于这个路径:
|
||||
|
||||
|
||||
```
|
||||
`https://example.com/ayushsharma-in/-/blob/master/_posts/2021-10-10-example.md`
|
||||
```
|
||||
|
||||
如果你在任何文章的 `page.path` 前加上 `https://example.com/ayushsharma-in/-/blob/master/`,它就会生成一个返回其源码的链接。
|
||||
|
||||
在 Jekyll 中,生成这个完整的链接看起来像这样:
|
||||
|
||||
|
||||
```
|
||||
`<a href="{{ page.path | prepend: site.content.blog_source_prefix }}" target="_blank">View source</a>`
|
||||
```
|
||||
|
||||
就是这么简单。
|
||||
|
||||
### Jekyll 和开放网络
|
||||
|
||||
现代网络是一种错综复杂的多层次技术,但这并不意味着它必须混淆。有了 Jekyll 的变量,你可以确保你的用户可以,如果他们愿意,了解更多关于你是如何建立你的网站的。
|
||||
|
||||
你可以在我的[个人博客][5]上看到真实的例子:滚动到底部的查看源码链接。
|
||||
|
||||
* * *
|
||||
|
||||
本文改编自 [ayush sharma 的笔记][6],并经许可转载。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/21/12/reveal-source-code-jinja2-git
|
||||
|
||||
作者:[Ayush Sharma][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/ayushsharma
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/browser_blue_text_editor_web.png?itok=lcf-m6N7 (Text editor on a browser, in blue)
|
||||
[2]: https://opensource.com/article/21/9/build-website-jekyll
|
||||
[3]: https://opensource.com/article/19/9/introduction-markdown
|
||||
[4]: https://jekyllrb.com/docs/variables/#page-variables
|
||||
[5]: https://www.ayushsharma.in
|
||||
[6]: https://www.ayushsharma.in/2021/11/linking-jekyll-pages-back-to-their-git-source-code
|
Loading…
Reference in New Issue
Block a user