Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持非根URL/Add support for non-base url #270

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

axmmisaka
Copy link
Contributor

Reference to static files were absolute and did not support Jekyll's
baseurl parametre, which, if the website is deployed with a url that is
not root (e.g. mirrors.tuna.tsinghua.edu.cn/mirrors), a 404 will be
returned when fetching static files as they are not correctly
referenced, causing the website to display that javascript was not
supported by the browser.
对静态文件的引用是绝对的(默认其在根目录下),并且不支持Jekyll的 baseurl 参数。这样一来,如果网站被部署在非根目录下(比如mirrors.tuna.tsinghua.edu.cn/mirrors),由于静态文件没有被正确引用,在访问它们时会导致404,网站则因此会显示浏览器不支持JS。

To solve this issue, this Q&A is referenced:
我参考了这个论坛问答,
https://talk.jekyllrb.com/t/relative-url-and-baseurl/2051,
by changing
href="/static/114514.js" to "{{ site.baseurl }}/static/114514.js"
we can eliminate the problem.
如此修改可以解决这个问题。

Nevertheless, it should be noted that there may possibly be other
static references which this single commit did not cover.
不过,这个commit不一定修复了所有的静态引用(∮ ′⌒`)

Copy link
Contributor

@ZenithalHourlyRate ZenithalHourlyRate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to your link to a discussion and this doc, it seems that the liquid filter relative_url is a better choice. Also, not all absolute paths have been fixed (Not limited to files changed in this PR). I will only merge if all these changes are made.
从你给出的讨论和我查阅的文档来看,使用 relative_url 似乎更好。同时,还有很多绝对路径没有被修复。我只会在全部修复后合并该请求。

@ZenithalHourlyRate
Copy link
Contributor

Thank you for your continuous effort in implementing this feature. However, as far as I know not all absolute paths have been fixed, for example, srcset in your changed lines and other files, /legacy_index in _include/legacy_notes.html, $.getJSON("/static/tunasync.json" in static/js/index.es6, etc.
首先,感谢你的持续关注和工作。但是我依旧注意到还有一些绝对路径没有被修复,比如你更改的文件以及尚未更改的文件中的 srcset,比如 _include/legacy_notes.htm/legacy_index 部分,比如 static/js/index.es6 中的 $.getJSON("/static/tunasync.json",不一而足。

Also, there is inconsistency in your changes, namely mixing {{ site.baseurl }} and {{ absolute | relative_url }} together. I hope we can pin to one style.
同时我也注意到一些代码风格上的不一致,即混用 {{ site.baseurl }}{{ absolute | relative_url }}。希望能保持同一个风格。

Since there are enormous codes using absolute paths, fully implementing this feature may be time-consuming as you and we need to develop and test it. It may be better to maintain your own fork, take time to fix all the absolute paths, and mark this PR as a draft before it is ready to get it upstreamed.
因为大量现存代码使用了绝对路径,完整支持相对路径可能需要消耗较多时间,毕竟你和我们都需要开发与测试这一功能。就现在的情况来看,你先自行维护一个分支、逐渐修复绝对路径、并在功能完备、能被上游合并之前将这个 PR 标记为草稿可能会更好。

@Harry-Chen
Copy link
Member

用一种语言就行,不用这么累

@axmmisaka
Copy link
Contributor Author

axmmisaka commented Jun 18, 2021

  1. 雀食,我的demo在http://hellfire.ocf.berkeley.edu:12345/_site ,最近沉迷游戏,目前还停留在哪崩修哪
  2. 看起来{{ absolute | relative_url }}这种过滤器式用法是推荐的用法,但与此同时,看起来Jekyll的液体过滤器是静态的,因此按我的理解似乎只能在js中使用{{ site.baseurl }},不能使用过滤器?
  3. 雀食,让我标记为草稿,到时候squash一下

@axmmisaka axmmisaka marked this pull request as draft June 18, 2021 16:47
@axmmisaka axmmisaka marked this pull request as ready for review July 27, 2023 09:12
@axmmisaka
Copy link
Contributor Author

axmmisaka commented Jul 27, 2023

昨日夜观加州天象,见一老者,曰:“你毕业前不把咕咕掉的PR解决,天必诛之!”,遂着急忙慌回到电脑前,复活此PR;冥冥之中又曰:“汝咕咕太久,开发太快,合并冲突已不可避。重置分支,放弃更改,重振旗鼓,从头开始,再强制推送到远端,可解合并冲突:此乃正道矣”
简单测试了一遍,貌似没有问题

同时我也注意到一些代码风格上的不一致,即混用 {{ site.baseurl }} 与 {{ absolute | relative_url }}。希望能保持同一个风格。

index.html中还是包含{{ site.baseurl }}的,这是迫不得已的必要邪恶。Jekyll 的液体过滤器只能进行静态处理,因此它无法正确对 Vue v-bind 中函数返回值进行过滤。经过权衡,我决定不采用以下几种替代方案:

  1. 更改index.es6中的getURL()。这种做法同样需要使用{{ site.baseurl }},而且需要更改两处(65行、63行或14行)
  2. 直接更改原始URL。这种方案不可行,因为一些URL是直接从镜像名称推导衍生的。

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants