Octopress deploy to project[gh-pages] css js

可紊 提交于 2019-12-13 05:11:48

问题


I want to setup octopress blog on gh-pages branch of one of my github projects. I follow guidelines from the octopress deployment docs. My project repository url is standard: https://github.com/my_user_name/project_name

I follow two scenarios by neither works in some way.

Scenario 1:

I invoke rake setup_github_pages and supply it with repository location: git@github.com:my_user_name/project_name.git This works well and gh-pages branch is created in my project repo.

I do not change Jekill setup in _config.yml, in particular root: is empty.
rake generate && preview work well. I load the site on local host:4000. Css and js are loaded correctly.

Now I deploy the site: rake generate && deploy I load octopress blog as: http://my_user_name.github.io/project_name/

Problem: the blog loads without screen.css. Moreover, I see following errors for javascript:

[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (jquery.fancybox.pack.js, line 0) http://my_user_name.github.io/javascripts/jquery.fancybox.pack.js

Scenario 2:

Same as above, but I change _config.yml, in particular is set root: /project_name to the name of my project repo.

rake generate && preview I load the site on local host:4000 and now I get errors, but on my local machine:

For screen.css, jquery.fancybox.pack.js and

[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (slash.js, line 0) local host:4000/project_name/javascripts/slash.js

Now I deploy the site: rake generate && deploy Css loads correctly, while error console shows that I searches for javascript not in my project path, but at my main repo path:

[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (jquery.fancybox.pack.js, line 0) http://my_user_name.github.io/javascripts/jquery.fancybox.pack.js


Please advice, what am I doing wrong?

Do I use rake setup_github_pages incorrectly?
Do I setup root in _config.yml incorrectly?
Or is there some additional setup information that has to be resolved?


回答1:


Answering myself. There are two issues here.

First, rake set_root_dir[dir_name]. This has never been mentioned on StackOverflow: There is a separate step specified for deploying projects to Github's project pages (not user pages) in addition to what is specified in http://octopress.org/docs/deploying/github/. Unfortunately it's not directly seen in that documentation. The step http://octopress.org/docs/deploying/subdir/ requires running rake set_root_dir[project_name] and a few modifications to Rakefile and config.rb. This resolves the paths correctly for octopress published in Github's project pages ([gh-pages] branch) or in subdirectories.

The second issue seems to be related to how the paths to resources (jquery.fancybox.pack.js in my case) have to be resolved for custom themes, when octopress is deployed to Github's project pages (subdirectory). One has to check that a custom theme has paths adjusted to {{ root_url }} for fonts, css and js as well.



来源:https://stackoverflow.com/questions/22498640/octopress-deploy-to-projectgh-pages-css-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!