GitHub hosted Jeykll site. Background images within css are not displaying? - github

I've created a settings.yml within a _data folder. This also contains my baseurl: /run-and-roll.
So I have inserted {{ site.data.settings.baseurl }} in front of my assets. The css file is loading along with images that are defined in the html. However, any background images requested in the css are not showing?
https://granttransition.github.io/run-and-roll/

Every configuration variable that appears in https://jekyllrb.com/docs/configuration/ makes sense to keep them there.
Usually templates preppend the base url when generating some urls like the ones of the assets, using {{site.baseurl}}, so if you manually sets it from another location it won't be used by default.
What you have read that is a good practice to have settings and config separate is for every other configuration not related exactly with jekyll built-in variables, that it is a good practice to put them on data files, so you keep your _conf.yml as clear as possible as the official docs suggests, that makes easier to maintain and update your Jekyll instance:
In addition to the built-in variables available from Jekyll, you can
specify your own custom data that can be accessed via the Liquid
templating system.
Jekyll supports loading data from YAML, JSON, and CSV files located in
the _data directory. Note that CSV files must contain a header row.
This powerful feature allows you to avoid repetition in your templates
and to set site specific options without changing _config.yml.
Plugins/themes can also leverage Data Files to set configuration
variables.

TL;DR
just put baseurl in _config.yml as suggested in other answers :)
b/c if you are using Jekyll with Github Page, then if site.url or site.baseurl are not specified, in a CNAME or config.yml, for the production build. then they will be set automatically by github page generator
Explanation
from github page generator code-source:
# Set `site.url` and `site.baseurl` if unset and in production mode.
def set_url_and_baseurl_fallbacks!
return unless Jekyll.env == "production"
repo = drop.send(:repository)
site.config["url"] ||= repo.url_without_path
if site.config["baseurl"].to_s.empty? && !["", "/"].include?(repo.baseurl)
site.config["baseurl"] = repo.baseurl
end
end
the default build environment for jekyll, is development. So while, working on your site locally. every thing will run just as you expect. even when putting baseurl in other location than _config.yml
but in github page side, the web site is built with this command:
JEKYLL_ENV=production jekyll build
and site.url and site.baseurl are overridden.
in your case, if you're using {{ site.data.settings.baseurl }} to access some page, and it's set to a value like ('' or '/') you may not notice a navigation issue. bat assets path for css and js will not work as expected.
So, just put baseurl in the _config.yml, refactor your layout and pages accordingly. and you'll be fine.
a side note: as mentioned in #David answer, it's the jekyll convention to put website setting. in _config.yml, but if you want to put them in other place, you can. just make sure, to declare them for the production build as will.
see also: Clearing Up Confusion Around baseurl -- Again
UPDATE
even after moving the website to a github project repo: /<user-name>.github.io/<repo-name> instead of user (or organization) repo: /<user-name>.github.io. you need to set as follows:
site.baseurl: ''
or just remove it. since you serve your website from the main repository (cf. above refence)

Use of {{ site.baseurl }} is a jekyll convention, moving it to a data file is not a good idea.
Nevertheless from your css standpoint, path to runner.jpg will always be ../assets/img/runner.jpg. No need to use baseurl.

Related

TYPO3 extension - f:uri.resource returns wrong path

I'm writing a backend module for my own TYPO3 extension, where I'm wrapping the content into a be.container including a CSS and a JS file:
<f:be.container
includeCssFiles="{0: '{f:uri.resource(path:\'CSS/backend.css\')}'}"
includeJsFiles="{0: '{f:uri.resource(path:\'JS/backend.js\')}'}"
>
<!-- module content -->
</f:be.container>
None of those resources gets included though. When I'm rendering f:uri.resource directly into the HTML, it - no matter which path - resolves to
/typo3/
which makes no sense to me. In my project, /typo3/ is the path where the TYPO3 core is symlinked to, relative to my web path.
I've assured that my resource files are placed in EXT:my_extension/Resources/Public/CSS/backend.css and EXT:my_extension/Resources/Public/JS/backend.js respectively. I had a similiar issue including resources in the frontend, where it would resolve to just a / - in the end I decided to go with inclusion via Typoscript instead. I'm not sure if I'll be able to do this for the backend module as well. Any idea how to solve this? Maybe I missed something in the configuration which messes up path resolution for f:uri.resource. Any help would be appreciated.
For a minimal test case, try putting the plain output into your fluid template:
{f:uri.resource(path:'CSS/backend.css')}
If that yields the same result, it seems like the ViewHelper is not aware of the current extension. You can pass it the extension key as argument, see https://docs.typo3.org/other/typo3/view-helper-reference/9.5/en-us/typo3/fluid/latest/Uri/Resource.html.

GitHub relative internal repository links in PULL_REQUEST_TEMPLATE.md

Using a relative link as directed (https://help.github.com/articles/about-readmes/#relative-links-and-image-paths-in-readme-files) in a PULL_REQUEST_TEMPLATE.md does not relatively link correctly.
When viewed in an actual PR:

[CONTRIBUTING.md](/.github/CONTRIBUTING.md)
routes to: https://github.com/.github/CONTRIBUTING.md.
[CONTRIBUTING.md](.github/CONTRIBUTING.md)

[CONTRIBUTING.md](./.github/CONTRIBUTING.md)
route to:
https://github.com/owner/repo/compare/.github/CONTRIBUTING.md
instead of https://github.com/owner/repo/.github/CONTRIBUTING.md.
Changing to ../ to go up a level would work for PRs, but would break the link when viewed in the GitHub UI.
Clicking the link as viewed on GitHub works: https://github.com/fs-webdev/fs-dialog/blob/master/.github/PULL_REQUEST_TEMPLATE.md, just not inside a PR.
(I feel like this used to work in 2017)
What is the correct way to have the relative link function as expected in both cases?
Background
Unfortunately, the given implementation seems to consider only the current
URL instead of the actual file path in the repository.
The same limitation can be noted when creating issues (through e.g.:
https://github.com/owner/repo/issues/new):
[CONTRIBUTING.md](.github/CONTRIBUTING.md)
->
https://github.com/owner/repo/issues/.github/CONTRIBUTING.md
Workaround
I only managed to make the relative link work by specifying the full URL
path (including the leading /):
[CONTRIBUTING.md](/owner/repo/.github/CONTRIBUTING.md)
->
https://github.com/owner/repo/.github/CONTRIBUTING.md
With that said, the abstraction can only go up to the URL host (i.e.:
https://github.com).

TypoScript: Check if JS/CSS File is already included

anybody knows how to check if a js/css file is already included with typoscript?
Example
[Template_A.ts]
page.includeJS {
jsfile = fileadmin/Template/js/jquery-1.10.2.min.js
}
now if i got an extension with the same include e.g.
[Extension_A.ts]
page.includeJS {
jsfile = fileadmin/Template/js/jquery-1.10.2.min.js
}
Is there a way to prevent this kind of double code injection? Maybe i got another Template e.g. Template_B.ts where jquery is not included - than the Extension_A.ts has to include jquery by itself.
Kinldy
You can use the same key inside includeJS such it just gets overridden if you include the file twice.
Other than that you should put jQuery into includeJSlibs, such that it is loaded before the other JS files.
Other than that, the TS should be unique for each page. Therefore you always to make sure anyway that all resources are included in-order.
You should not include JS libs with the automatic extension TS setups. Use your documentation to tell the integrator what needs to be included and what not.
The various and independent inclusion of scripts by plugins and templates is one of the tricky points in TYPO3. As far as I know, this point cannot be managed at one single point.
There is a plugin "t3jquery" that offers to build, compress and share a common jQuery library. It also has a service to analyze other plugins for their dependencies. But this doesn't solve the problem in general, as many plugins don't check for libraries already loaded.
The most stable way is to remove all plugin's references to libraries manually in your TypoSkript. This gives you some simple additional TypoSkript lines. I use lines like these:
plugin.tx_imagecycle_pi1.file.jQueryLibrary >
plugin.tx_imagecycle_pi1.jQueryLibrary >
plugin.tx_multicontent_pi1.file.jQueryLibrary >
plugin.tx_multicontent_pi1.jQueryLibrary >
# Fluid
page.headerData.998 >
You can find the matching TypoSkript descriptors by searching for the library name in the TypoSkript browser or by greping in the plugin's source code. You will also need this if you wish to add libraries as part of content that was get by AJAX, thus separating the libs from the page content.
Here's a tut (in German): http://jweiland.net/typo3/typoscript/javascript-manuell-entfernen-oder-einbinden.html
Futher possibilities you can check:
Some plugins are written in good structure and offer to keep back their Javascript in the settings.
Some script inclusions may come rather from the static template but from a plugin, so don't forget to have a look there.

In TYPO3 6.x, how to get defaultJS, when config.disableAllHeaderCode is enabled?

I set config.disableAllHeaderCode = 1 in my recent TYPO3 sites, as I want full control over the page template.
But this not only throws out the html tag etc., but also the default Js (which could be used to uncrypt mailto-Links.
One solution would be to copy this TYPO3-generated JS from the core code and insert it manually. Very simple: just set config.disableAllHeaderCode = 0, load the page once, copy the js, done. But, in case of an update or settings change, this might break.
So: is it possible to access this "default JS" via typoscript and assign it to the PAGE object?
Have a look at https://github.com/TYPO3/TYPO3.CMS/blob/master/typo3/sysext/frontend/Classes/Page/PageGenerator.php. You will see that the spam protection code is hardcoded and only added to the page output if config.disableAllHeaderCode is not set.
Therefore I don't see a possibility to do that. Therefore the answer seems to be no, unless you XCLASS the PageGenerator. I would just copy the JavaScript code; I'm using TYPO3 for some years now and wouldn't remember that the spam protection code ever changed.
There is a solution I think. Go to /typo3/sysext/cms/tslib/templates. There is a file tslib_page_frontend.html. This file is responsible for rendering the whole page including the head. You can define a new path to the above mentioned file. For example set the following code:
config.pageRendererTemplateFile = PATH_TO_YOUR_THEME//Resources/Private/Core/tslib_page_frontend.html
respectively
page.config.pageRendererTemplateFile = PATH_TO_YOUR_THEME//Resources/Private/Core/tslib_page_frontend.html
The new template file can look like the following small snippet:
###JS_INLINE###
###BODY###
That way the inline JS is still rendered (and I think the spam protections JS is inline JS - which can be stored in external files).

Reference GitHub file in jsFiddle

Is there a possibility to misuse grab files from a github repo as external resources in jsFiddle?
TLDR; Visit rawgit.com which will pop your files on a CDN straight from GitHub so you can use them.
Unfortunately none of the answers here worked for me. The rawgithub URL didn't seem to work as the connection gets refused. So here's a full solution that did work. Firstly in GitHub you need to click the Raw button to get the original JavaScript.
Then copy the URL from the page it takes you too. You'll notice if you try and use this directly you'll get a warning from JSFiddle.
More to the point is the browser will give you an error, e.g.:
Refused to execute script from https://raw.githubusercontent.com/nnnick/Chart.js/master/Chart.min.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
Take that URL and visit rawgit.com. This will give you a URL of the format https://rawgit.com/nnnick/Chart.js/master/Chart.min.js which you can then use.
I've tried and tested this and it seems to work fine without issue
This is an updated answer, since the url's have changed slightly for Github... I ran into this issue and figured it out for present day. Hopefully this helps people out finding this post recently. Example for Bootstrap Slate theme from Bootswatch:
Raw file url: https://raw2.github.com/thomaspark/bootswatch/gh-pages/slate/bootstrap.css
Remove the 2. after raw: https://rawgithub.com/thomaspark/bootswatch/gh-pages/slate/bootstrap.css
That's it! :D
Nowadays JSDelivr seems to be the best option.
UPDATE
How to use or misuse github as kind of a CDN is not a thought that only benign "fiddlers" have; criminals have that thought also. Unfortunately, github, being as free and as anonymous as it is, is prone to be misused. As far as I can tell, the fact that some of the above solutions are things which are now broken, has to do with that.
Here is how I do it. It works now (Nov 2019), but it's admittedly not very convenient.
Get a github account yourself, if you don't already have one. Create a repository the name of which is identical to your github user name. That repo (and only that repo), - I'll call it the "home repo" - you can use as your web hosting service. https : // yourGithubUserName .github.io will show your home repo "raw/as it is" to the public. (Folder contents is not shown, and you HAVE TO have an index.html)
Now, if you want to use someone else's github repo in a fiddle, just copy over the complete repo to your home repo, and then just reference your copy of that repo with the src attribute of a script tag in the HTML part of the fiddle. Like this:
<head>
<script src="https://mathheadinclouds.github.io/thirdparty/esprima.js"></script>
<script src="https://mathheadinclouds.github.io/thirdparty/estraverse.browser.js"></script>
<script src="https://mathheadinclouds.github.io/thirdparty/escope.browser.js"></script>
</head>
<body></body>
Above snippet shows the HTML part of a working fiddle which is using the node modules esprima, estraverse, and escope, which is to say, the github repos of the same name. thirdparty is there because that's the name of the subfolder (in my home repo) where I put the copies.
As I said, not very convenient (lot's of copy and paste to set it all up), but that's what works for me.
And I should mention, just copy/paste might not be enough, you might have to do browserify or webpack on the referenced repo (if it was made for node, that is.)
here is the fiddle I was talking about.
OLD ANSWER
(works, but is kind of slow)
You can use requirify. It's made to enable you to require (as it is in node) on the browser command line; but it works in fiddles too, I tested it. I have no clue if it's "the best", compared to the other methods above (since I didn't go through them all and tested them), but it works.
Here is an example fiddle loading esprima (javascript parser), then escodegen (reverse javascript parser depending on esprima), then parsing and regenerating some simple javascript code.
what
require('lorem', 'ipsum')
does is, it loads the ipsum node module from npm, and puts the result into global variable named lorem. So this is only for npm modules not general github files which aren't also node modules. Shouldn't be much restriction since you can always turn it into a node module if it's your own project.
here it is
second example using same technique.
(((it's actually even simpler as shown in the fiddle. You can just put the 2 require statements right one after the other, you don't need a callback function in between (just one callback function to wait until both are loaded))))
Another possibility is to add the Git library to the cdnJS Script Repository (they write that any library that is resonably popular on GitHub will be accepted) and then use it as external resource.
Just found out: there are lots of Javascript libraries at http://jsdb.io/ and it's very easy to add new ones there--i's just a matter of entering the URL of a Github repository.
If there is a git repo in following folder structure
fiddletest/test1 (fiddletest is the repo name and test1 is a folder)
then the corresponding jsfiddle link will be
http://jsfiddle.net/gh/get/<library name>/<version>/<github user name>/fiddletest/tree/master/test1/
The folder and file structure must be like this
fiddletest(the repo name)
|____ test1
|____ demo.html
|____ demo.js
|____ demo.css
|____ demo.details
except these three files others will be ignored.
the details file should hold the fiddle details and link of external resources(if any) as follows
---
name: test fiddle repo
description: this is a test repo
resources:
- http://abc.xyz.com/abc.js
- http://abc.xyz.com/abc2.js
...
May be you have noticed the and in the fiddle link. If a fiddle is with pure js the the library name should be "library" and the version should be "pure"
In a nutshell the fiddle link to reffer to github should be in following format
http://jsfiddle.net/gh/get/<library name>/<version>/<github user name>/<repo name>/tree/<branchname>/<folder name>/
2021
Just go to github file and click "Download" button and copy URL - it will works with fetch - working example here (it not works in SO snippet - I don't know why) - example url from this file:
https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/VC/glTF-Embedded/VC.gltf