ElFitz
ElFitz

Reputation: 988

How to generate a whole website in a variabilized sub-directory ? (Jekyll)

I've been playing around with Jekyll lately and recently discovered that S3 wouldn't allow me to have enough buckets to have one bucket per website.

So I'm struggling to figure out two things

1) How do I specify that I want a 'child' subdirectory to be created, and all the generated website's files to be in it ?

2) How do I use a variable as the 'child' subdirectory's name ? (since it will be different for each website)

The baseurl config option doesn't seem to do anything about that. Any idea will be welcome :-)

Thanks a lot, and have a great day !

Upvotes: 0

Views: 413

Answers (1)

Peach
Peach

Reputation: 2787

I'm not sure about the variable option, however, for child sub-directories:

A) If you can put the content into "child" folders directly within the jekyll content, then use different configuration files to manage each site through build properties. See the examples under the example below.

B) If you just want to put the same content in different places, perhaps you could use different baseurl or destination properties in different config files? Use the same config file approach as below, but with different versions of those properties instead of/in combination with the exclude property (see https://jekyllrb.com/docs/configuration/#serve-command-options).

Example: Use different config files

Use the exclude config property to exclude folders (and all of that folder's contents) when running a build. You could also specify different output folder locations per site, base URLs, and so on. I'll focus on the exclude property, but you can find other useful properties in the documentation: https://jekyllrb.com/docs/configuration/#global-configuration

For example, you could have the following files/folders:

/siteA-folder/siteA-content/blah.html
/siteB-folder/siteB=content/meh.html
/siteC-folder/siteC=content/foo.html
config.yaml
config_buildA.yaml
config buildB.yaml

Use the build option --config FILE1[,FILE2...] (https://jekyllrb.com/docs/configuration/#build-command-options) to explicitly call your custom config file A or B, each of which has its own version of the exclude property.

Snippet from config_buildA.yaml:

exclude: 
  - /siteB-folder/ # While building A, you want to exclude the siteB folder and contents
  - /siteC-folder/ # Similarly, exclude siteC contents

Snippet from config_buildB.yaml:

exclude: 
  - /siteA-folder/ # While building B, you want to exclude the siteA folder and contents
  - /siteC-folder/ # Similarly, exclude siteC contents

Building A from the command line:

jekyll build --config config_buildA.yaml

Building B from the command line:

jekyll build --config config_buildB.yaml

By managing excludes in the config file, you can re-use the common templates and css, and keep everything together (using less disk space overall).

If there's shared content, you could also look into using a more advanced feature, includes (see https://jekyllrb.com/docs/includes/), to manage the shared content in the includes folder, referenced within the html or markdown files (but that's getting a little of the beaten track for your question, so I'll stop there...)

EDIT: I see you've edited the question specifying the baseurl property doesn't do what you're looking for.

I've used a combination of the url site property baseurl and destination similar to below. In my case, I have different destinations depending on whether it's an archive or latest content, but you could use this to build to different web folders if you wanted.

Ex: config for latest content

url: http://example.com
baseurl: "/latest/"
destination: /path/to/latest/output/

Ex: config for archived content

url: http://example.com
baseurl: "/archive/content/"
destination: /path/to/archive/output/

Then, using the multiple versions of the config file, I can just call whichever one applies.

Upvotes: 2

Related Questions