HTML folder structure - html

In my Dynamic Web Project, I have the following folder structure relative to the WebContent folder:
WebContent/
├── META-INF/
├── WEB-INF/
└── index.xhtml
So if I deploy my application to the server I can access it at the location: localhost:<port><context-root> which would display the index.xhtml file under the WebContent folder. I have other sections that I would like to put in their own folder. But simply for organizational reasons, it'd be nice to have all the static files, such as the XHTML files, in its own folder like:
WebContent/
├── META-INF/
├── WEB-INF/
└── Static/
├── Section/
│ └── index.xhtml
└── index.xhtml
But now if I point to localhost:<port><context-root> it won't open the index.xhtml file (because it's now located under the /Static folder). Is there a way to have localhost:<port><context-root> "point" to my Static directory without displaying it in the URL (without showing /Static)?

You can configure the <welcome-file-list> in your web.xml, where you can specify the file you want to visit as default page.

Related

django to find static css files for my HTML page

I'm trying to reach some of my css files but I can't seem to get the directory right.
For example I have a link in my home.html:
<link href="assets/plugins/revo-slider/css/settings.css" rel="stylesheet" type="text/css"/>
I've converted it to:
<link href="{% 'assets/plugins/revo-slider/css/settings.css' %}" rel="stylesheet" type="text/css"/>
But that's the incorrect directory because I recently moved the file to where it is now as shown below.
my folder structure is as follows:
project/
├────── Index/
│ ├──_static/
│ │ ├── css/ (.css files)
│ │ ├── js/ (javascript files)
│ │ ├── img/ (images files)
│ │ ├── media/ (video files)
│ │ └── plugins/ (.css plugin files)
│ │
│ └── templates/
│ └── index/
│ ├── home.html
│ └── about.html
├── manage.py
└── project folder with settings.py,url.py
my settings.py includes:
line 5: BASE_DIR = Path(__file__).resolve().parent.parent
line 90: STATICFILES_DIRS = [
"/index/static",
]
I've checked the similar questions and youtube tutorials but I've seen some which suggested I add:
os.path.join(BASE_DIR, 'static')
in line 91 but i've seen conflicting codes through Youtube tutorials, first step is getting the directory right in my html though, if anyone can help it'd be great
First of all, don't specify your static files directory (in line 90 in your case). If you use the name static for your directories, Django automatically discovers them. You can get rid of that entire line. Just be sure to use static name for your directories always.
For some reason if you want to specify your static directories, just use the directory name, don't specify the path. i.e.:
STATICFILES_DIRS = [
"/index/static",
]
should be:
STATICFILES_DIRS = [
"static",
]
Secondly, you should always namespace your static file directories. For example, in the static directory of each app, first, create a directory with the same name as the app name and keep your static files in there. This will let you use different static files even with the same names without any conflicts. Here is my suggested structure.
.
├── manage.py
├── my_app
│   └── static
│   └── my_app
│   ├── css
│   │   └── style.css
│   └── js
│   └── script.js
├── project
│   └── settings.py
└── static
And in your templates, you can use static files like this:
<link rel="stylesheet" href="{% static 'my_app/css/style.css' %}">
In development, Django will automatically discover your static files. And before pushing the project live in production, run python manage.py collectstatic and your static assets will be copied to the static directory in the project root. To make this work, you need to specify the static root path so Django will copy static assets from each app to the root static directory. Add this to your settings.py file:
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
This is what I always do. I find this to be a cleaner way to manage static assets as each of your apps can have independent static files and by namespacing your static directories, you will be able to avoid conflicts.
Okay I've figured it out, I just removed the 'assets' tag from the directory link but can someone double check I have the correct code in my STATICFILES_DIRS please, I've seen conflicting answers I have the latest version of django

Jekyll site working on GitHub Pages not working locally

Problem
Problem: I can't get a local build of my GitHub hosted website. My gh-pages branch on my local clone of my GitHub repo does not build right.
Specifically, markdown files don't build to the _site folder as html unless they start with the YAML frontmatter demarcation (--- newline ---), and when I serve them on localhost they don't pickup any CSS, I can't really preview what it will look like on GitHub. If the frontmatter demarcation is not in the markdown file it is copied to the _site folder as markdown.
You can see below I have two markdown files ideas.md and local-jekyll-build-theme-trouble.md.
ideas.md has the frontmatter things and builds as an html file that won't preview with any theme.
local-jekyll-build-theme-trouble.md doesn't have the frontmatter and 'builds' as markdown and 404s when I try to hit it in the browser (unless I add the .md extension in the URL, boo)
It doesn't make any difference if I have committed changes or not. It doesn't matter if I run jekyll via 'bundle exec' or not. I don't get any errors from jekyll (even when using the --trace option)
In Contrast...
When I push to GitHub, both pages seem to work properly. I can go to https://breedlovedesign.github.io/ideas/local-jekyll-build-theme-trouble without putting .md in the URL and https://breedlovedesign.github.io/ideas/ serves index.html fine. Both get all the lovely theme CSS as specified in my config.
I had assumed that both files were being converted to html but I double-checked and the _site folder on GitHub also has index.html and local-jekyll-build-theme-trouble.md.
_config.yml
theme: jekyll-theme-minimal
System Info
MacOS 10.15.6
Ruby Version
~/.../devo/ideas on gh-pages*
$ rbenv version
2.6.5 (set by /Users/johnbreedlove/Sync/devo/ideas/.ruby-version)
Gemfile
gem "github-pages", "~> 209"
Jekyll Build Output
~/.../devo/ideas on gh-pages*
$ bundle exec jekyll serve
Configuration file: /Users/johnbreedlove/Sync/devo/ideas/_config.yml
Source: /Users/johnbreedlove/Sync/devo/ideas
Destination: /Users/johnbreedlove/Sync/devo/ideas/_site
Incremental build: disabled. Enable with --incremental
Generating...
done in 0.616 seconds.
Auto-regeneration: enabled for '/Users/johnbreedlove/Sync/devo/ideas'
Server address: http://127.0.0.1:4000
Server running... press ctrl-c to stop.
Directory Structure
~/.../devo/ideas on gh-pages*
$ tree
.
├── Gemfile
├── Gemfile.lock
├── _config.yml
├── _site
│   ├── assets
│   │   ├── css
│   │   │   └── style.css
│   │   ├── fonts
│   │   │   ├──...
│   │   ├── img
│   │   │   └── logo.png
│   │   └── js
│   │   └── scale.fix.js
│   ├── index.html
│   └── local-jekyll-build-theme-trouble.md
├── index.md
└── local-jekyll-build-theme-trouble.md
10 directories, 30 files
Contents of /index.md
---
---
# icanhaz themes pls?
must I use YAML frontmatter?
Yes, you must use the YAML front matter. It is made explicit in the jekyll documentation.
Any file that contains a YAML front matter block will be processed by Jekyll as a special file. The front matter must be the first thing in the file and must take the form of valid YAML set between triple-dashed lines.
If you want to use Liquid tags and variables but don’t need anything in your front matter, just leave it empty! The set of triple-dashed lines with nothing in between will still get Jekyll to process your file.
If it works in GitHub Pages, I assume that it does a little preprocessing of its own. But for Jekyll alone, files without front matter are left as they are.

Generated link `/foo` for `_collection/foo.md` doesn't work work locally (but does on Github Pages)

I have the following file structure in my Jekyll project:
├── _articles
│   ├── bar
│   │   └── widget.md
│   ├── bar.md
│   └── phone.md
└── foo.md
See here: https://github.com/janpio/jekyll-test
_articles is a collection that is defined in _config.yml:
collections:
articles:
title: Articles
output: true
permalink: :path
On Github Pages this is built into these URIs:
https://janpio.github.io/jekyll-test/bar/widget
https://janpio.github.io/jekyll-test/bar
https://janpio.github.io/jekyll-test/phone
https://janpio.github.io/jekyll-test/foo/
See here: https://janpio.github.io/jekyll-test/
That is all fine and as expected.
But when I bundle exec jekyll s this project locally1 it doesn't work the same way. I get the expected URIs:
http://127.0.0.1:4000/bar/widget
http://127.0.0.1:4000/bar
http://127.0.0.1:4000/phone
http://127.0.0.1:4000/foo/
But the problem is that #2 gets redirected to 127.0.0.1:4000/bar/ and shows a directory listing instead of the actual page!
Looking at _site this is the file structure that is generated:
├── bar
│   └── widget.html
├── bar.html
├── foo.html
├── index.html
└── phone.html
So I can access bar.md at http://127.0.0.1:4000/bar.html.
How can I fix this?
1 My Gemfile is so the environment should be identical to Github Pages: https://github.com/janpio/jekyll-test/blob/master/Gemfile
Update for Jekyll 3.6.x
The 3.6.0 Jekyll release changed this behaviour:
Fix serving files that clash with directories (#6222) (#6231)
Unfortunately, these changes didn't really fix the problem but replace it with a less serious one: The link now doesn't show the directory listing any more but the correct page, but the path is still different in that it adds the / at the end. Unfortunately as a regression bar/widget doesn't render the correct content any more but shows bar.md.
These are the first solutions that come to my mind:
Stop using 'pretty URLs'
Use only index.md files (each of them in a seperate folder)
Prevent naming collisions between folders and files
Create an index.html file in the bar folder that redirects to bar.html (although that might create a redirect loop)
Update for Jekyll 3.7.x
The 3.7.0 Jekyll release included a PR that should fix this problem:
return correct file in dir if dir has same name as file

Custom URL for assets folder in Jekyll

I currently have a Jekyll project with this structure:
├── _config.yml
├── assets
| ├── js
| ├── css
| └── images
And my _config.yml looks like:
.
.
lang: en
destination: _site/en
.
.
So, when building the project all the site is inside the _site/en/ folder, this includes de assets folder with all my static assets (Images, css, js, etc).
Is there a way to build the page configuring a custom destination for the assets folder?
├── _config.yml
├── _site
| ├── en
| └── assets
I tried by adding this to my _config.yml (having installed jekyll-assets) without lucky:
assets:
dirname: assets
baseurl: /assets/
sources:
- assets
Since the root folder is now: /_site/en/ you need to step down a level.
Try using this:
../assets/
This will step down a directory out of /en/.
At the end, I'm building my site in several jekyll build executions. So, for me the simplest way of doing this is by excluding the assets folder for each language build and simply run a 'cp -a' of the assets folder to the _site/ folder. In this case, I avoid using another plugin and simply copy the files you need.

Keep files near generated files in Jekyll

I have a Jekyll blog and some of the raw posts have some additional files at the same level with the markdown file. For example:
.
├── _posts
├── first-post
├── 2007-10-29-first-post.md
└── download.zip
How can I and up with a generated structure such as
.
├── _sites
├── first-post
├── index.html
└── download.zip
The download.zip file needs to be in the same location as its dependent post (I cannot use any includes or other redirect tricks)
Try this jekyll-postfiles which is:
A Jekyll plugin that copies static files from the _posts to the _site folder