Jekyll: Include Menu at different levels makes problems - jekyll

I include an overall menu with jekyll at different pages.
So this menu is for example included in index.html but also at deeper levels like /portfolios/someportfolio.html.
Now the issue is that the menu links do not work at deeper levels.
They include the submenu path like .../<b>portfolios</b>/menuitem.html.
What can I do to address this?

If I understand it correct, you have a problem with relative URLs. Just use absolute URLs and you will be fine. Have your include link to this:
/menuitem.html
If you want to make it better you can add a base_url and/or even a site_url variable in front. Like this:
{{ site_url }}{{ base_url }}/menuitem.html
This will make it easier to move your site to a subdirectory.

Related

How do I make Django write the links to pages correctly?

I've set up my Django project website which is a maze generator, to have a navbar which buttons link to other pages I've made.
For example, the style page's directory is just /style, so it brings up the page with which reference is styles, then if I click the homepage button on the navbar it goes to /home all good.
But when I go to the individual maze pages which references is just a number(for example 3), if I click the navbar button to go to home instead of going to http://127.0.0.1:8000/home it tries going to http://127.0.0.1:8000/3/home which doesn't exist.
Is there a way to change how Django processes the links to remove the directory before it.
navbar html code
urls page in django
Assuming your urls.py is set up correctly, you can then use the {% url %} template tag like so:
...
And Django will automatically replace that with the actual URL called urlname. For this to work, your urls.py should have paths defined like so:
path("some/url/here", views.my_view_function, name="urlname")
The name attribute being the important part here.
By writing href="3" you are simply telling the browser to look for https://example.com/whatever/the/current/url/is/3, in other words, it's relative to the current position.
To make it absolute, you have to either start with / (which will make URLs relative to the current domain, for example href="3" will lead to https://example.com/3) or write it in full, including the https://example.com/ part, which will lead exactly where pointed to.
Django automatically takes care of this when you use the {% url %} tag.

jekyll correctly adding additional pages/broken links or css

I'm using jykell to create a personal website. Check it out here chrisCPO.com general feedback is welcome. Still a wip.
UPDATE: looks like some of the site root vars are not being rendered on added pages. Home link code is:
<a href="{{ site.baseurl }}">
which works but is being overridden on the additional page?
If you visit the site notice click on experience on the sidebar.Then try to go to the home page.
Issue is if I add a page like the docs say to I get all of my added pages in-site links are broken. They are rendering as
<a class="sidebar-nav-item" href="">Home</a>
instead of
<a class="sidebar-nav-item" href="/">Home</a>
notice the href.
note: both of these issues are on production only, everything works fine locally.
What is the correct way to add an additional page so everything works?
using jekyll 3.0
You need to set your CSS paths in your layout relative to the root of the site, like this: /css/style.css (notice the first slash). Then the choice for folders or no folders becomes irrelevant. Permalinks can be managed globally in the config file. See the docs.

Why are visitors to my site following absolute links as if they're relative?

Every page on my website has a navbar with some absolute links, to pages like /archive and /atom.xml. These are present on pages like /post/post-title.
In my access logs, I'm seeing heaps of requests for paths like /post/post-title/archive and /post/post-title/atom.xml.
Assuming that I haven't just stuffed up a link somewhere (i.e., missed a slash), is there something else I might be doing wrong that's causing some clients to follow absolute links as if they're relative? Or is it just weird bots being weird?
Links that have the forward slash before it should load at any folder in your web project with the main domain name.
If you have like this:
domain.com/index.php
domain.com/archive/index.php
and both index.php files have the following:
home
archive
all the links in both files are absolute links like:
home
archive
Having relative links could be produced from two issues:
1- Having a ./ rather than / in your links. (And that is the best guess)
2- Bots understands links and love links with "/" not with "http://domain.com/"
but you might uploaded a file with a ./ link before
and bots got it and you have it recorded.
Moreover, relative links are processed inside the main folder which they are inside, for example:
Putting the following:
Other Page
archive
inside:
domain.com/archive/index.php
will leed to:
Other Page
archive

Make kramdown's ALDs available on entire Jekyll site

I'm using Jekyll to make a site that makes frequent use of kramdown's attribute list definitions. However the only way I can make this work right now is to include all of the definitions in every page e.g.
{:def1: ...}
{:def2: ...}
{:def3: ...}
This seems really smelly to me since if I want to change a definition, I need to do so in every single page. Ugh.
Is it possible to put these definitions somewhere where they will be included in every page? I tried putting them in a layout but it seems that Jekyll won't parse markdown in layouts.
I'm also open to alternatives to ALDs if this is not the right way to go about things.
If you want to add definitions to your posts, you can also create an .md file in your _includes folder with definitions like:
*[def1]: ...
*[def2]: ...
And then you can add this file to every post using {% include definitions.md %}.
It shouldn't be in the _layouts folder. Try keeping it in the _includes folder and then include it with this tag {% include definitions.html %}

referring to .css and images from script-generated HTML

I have a site with static HTML pages in the home directory. These HTML pages use relative paths to refer to images, css, and links i.e.
<img src="images/myimg.gif">
and
Contact Us
I also have a monolithic script whose URL is, i.e. http://mysite.com/myScript which uses "extra path info" to select functions... i.e. http://mysite.com/myScript/products shows a list of products. So in HTML generated from the script I need to refer to images, css and links like this:
<img src="../images/myimg.gif">
and
Contact Us
The problem is now I want to start moving common HTML into include files, (e.g. common header and footer), but the fact that the script and the static HTML refer to relative resources in different ways is complicating matters.
I don't want to use absolute paths because that messes up my colleague's work when she tries to work on the pages in DramWeaver, and it also makes the site less flexible.
What's the best way to solve this issue? One idea I had was to use URL rewriting in Apache to allow the URL to http://mysite.com/products to really use http://mysite.com/myScript/products but I don't have experience with URL rewriting so I don't know how easy that would be. Another idea I had was to use the META BASE attribute in HTML but I don't like the fact that I would have to hard-code that into every HTML page, and it would have to have the full URL hard-coded (e.g. http://mysite.com/) into each one. Any advice?
Can't you refer to your images with a slash at the beginning so all files linked to are from the root, no matter how deep you are in the directory structure you are? E.g:
<img src="/images/myimg.gif" />
EDIT:
You could use $_SERVER to get the path then use substr_count to count the number of slashes in the path. Add as many ../'s as you need based on that number. Would that work for you?