Docpad alias plugin in the static environment - docpad

I'm trying to use the alias plugin to do the following:
I have this source structure
/src/documents
gettingstarted.html
manual.html
What I would like in the output is this:
/out/
gettingstarted.html
manual.html
index.html -> redirects to gettingstarted.html OR just copies the content of gettingstarted.html
I've tried to accomplish this with the alias plugin as follows:
alias:
hard: true
symlink: true
aliases: {
'/index.html': '/gettingstarted.html'
}
extensions: [ 'html' ]
Unfortunately this doesn't seem to do anything. Does the alias plugin even support the static environment?

The plugin does support static mode as long as you are using the hard: true option (which you are). Note, this will not redirect requests. Rather, it will create two URLs that have the same contents either by copying the source URL into the target URL or by creating a symlink at the target URL that points to the source URL.
I believe your problem is that you have the source/target mappings backwards. The documentation doesn't make it clear, but the config should follow this pattern:
alias:
aliases: {
'/source-file-that-exists.html': '/target-file-you-want-to-create.html'
}
So to copy gettingstarted.html into index.html you'd want:
alias:
hard: true
symlink: true
aliases: {
'/gettingstarted.html': '/index.html'
}
extensions: [ 'html' ]

Related

Jekyll default (layout) Front Matter doesn't work: fixed

I was trying to set different layouts depending on the directory of the pages, like:
defaults:
-
scope:
path: ""
type: "pages"
values:
layout: "default"
-
scope:
path: "www/grid"
type: "pages"
values:
layout: "grid"
-
scope:
path: "www/product"
type: "pages"
values:
layout: "product"
As recommended, I saved the _config.yml file, stopped and rerun the jekyll serve command. Yet, after reloading the pages, nothing seemed affected.
To solve the problem, I:
Saved the _config.yml file
Stopped the jekyll serve command
Deleted the .jekyll-metadata file
Run the jekyll serve command
After that everything worked fine.
The .jekyll-metadata (which I assume is some cache) file is rebuilt after the serve command.

How to get "_pages" referenced at the site root in Jekyll?

I have Jekyll site hosted on GitHub Pages. The file _config.yml has this content (excerpt):
# Defaults
defaults:
# _pages
- scope:
path: "_pages"
type: "pages"
values:
layout: "single"
read_time: true
So when the site is built, I can open a page by its URL like this:
https://repo.github.io/_pages/some-page/
I read all the docs for Jekyll but it is not clear to me how to turn this URL to be https://repo.github.io/some-page/ or maybe https://repo.github.io/pages/some-page/.
_pages can be seen as collection directory.
Therefore by simply having the following config:
collections:
pages:
output: true
will give you URLs like https://repo.github.io/pages/some-page.html
To get custom URLs you may add a permalink sub-config:
collections:
pages:
output: true
permalink: /:collection/:path/
will give you URLs like https://repo.github.io/pages/some-page/
For more possibilities, refer the official docs

Laravel Mix and SASS changing font directory

I'm using Laravel 5.4 and Laravel Mix to output SASS files.
In my font definitions I'm configuring them so that when the CSS is output it will point to files such as public/assets/fnt/font-name/filename.ext but the processor changes the output so that it will instead point to public/fonts/filename.ext. Is there a way to stop it from changing the output paths?
It makes little sense to me that it would do something like this by default.
Edit
I've seen that the defaults they're using in Mix are the culprit:
module.exports.module = {
rules: [
// ...
{
test: /\.(woff2?|ttf|eot|svg|otf)$/,
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]?[hash]',
publicPath: '/'
}
}
]
};
I've tried using null-loader instead of file-loader but instead it causes it to fail because it can't find the files in node_modules which is not where it should be looking in the first place.
Removing the rule in question results in a flood of errors from trying to open and evaluate the font files in question:
error in ./public/assets/fnt/fanfare-jf/fanfare-jf.ttf
Module parse failed: DIRECTORY\public\assets\fnt\fanfare-jf\fanfare-jf.ttf Unexpected character '' (1:0)
You may need an appropriate loader to handle this file type.
(Source code omitted for this binary file)
# ./~/css-loader!./~/postcss-loader!./~/resolve-url-loader!./~/sass-loader?sourceMap&precision=8!./resources/assets/sass/app.scss 6:2525-2590
# ./resources/assets/sass/app.scss
# multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss
I can at least add emitFiles: false to options to prevent it from making copies of the file, but the paths are still being altered.
I ended up with the following configuration to at least get it to a working state.
let assetDir = 'assets/build';
mix.config.fileLoaderDirs.fonts = `${assetDir}/${mix.config.fileLoaderDirs.fonts}`;
mix.config.fileLoaderDirs.images = `${assetDir}/${mix.config.fileLoaderDirs.images}`;
mix.sass('resources/sass/app.scss', `public/${assetDir}/css`)
.js('resources/js/app.js', `public/${assetDir}/js`);
Updated:
In newer versions this has been made customizable via mix.options() and can be adjusted as below:
let assetDir = 'assets/build';
mix.options({
fileLoaderDirs: {
images: `${assetDir}/img`,
fonts: `${assetDir}/fonts`
}
});
// adjust build commands accordingly, for example:
mix.js('resources/js/app.js', `public/${assetDir}/js`);
The output you got is the intended behaviour due to your configuration.
You are using this configuration to load the file:
options: {
name: 'fonts/[name].[ext]?[hash]',
publicPath: '/'
}
Which says use the publicPath as public and create a file with the name fonts/[name].[ext]?[hash] and webpack knows about what these symbols '/', '.', '?' in the name do.
It just looks for the fonts directory and if there is no any fonts directory it creates a new one and place the files into that directory.
So, you need to use this configuration for your folder structure:
options: {
name: 'assets/fnt/font-name/[name].[ext]?[hash]',
publicPath: '/'
}
This should work for your configuration.
More on file-loader configuration:
https://github.com/webpack-contrib/file-loader#filename-templates
Edit:
Since Laravel Mix uses Webpack in it's background and Webpack doesn't have any knowledge of the fonts file when there is no any appropriate loader added to the configuration. So, the error:
Module parse failed: DIRECTORY\public\assets\fnt\fanfare-jf\fanfare-jf.ttf Unexpected character '' (1:0)
You may need an appropriate loader to handle this file type.
is occurred.
You need to tell the Webpack to load the fonts to your desired directory and the fonts linked in your SASS file will be linked by the Webpack without any more configurations.

Is it possible to extend a .scss-lint.yml config file

Is there supported syntax to extend a .scss-lint.yml config file in the same way that you can extend a .jshintrc config file?
My goal is to pull all config files from a node package.
So a jshint would look something like this:
{
"extends": "./node_modules/npm-package-name/shared/.jshintrc",
"browser": true
}
I'm not sure how to pull off a scss-lint file.
Yes, it is possible through config-file setting:
Example:
options:
config-file: ./node_modules/#my-shared-repo/configuration/sass-lint.yml
convention: hyphenatedbem
rules:
class-name-format: 1
As of now this is not possible. A workaround solution is to create a symlink to the scss-lint file.
ln -s path/to/symlink/filename filename

How to use YML files for a Mojito project?

It is said that Mojito can use JSON or YML as the application.json (the config file), but I haven't seen YML examples around?
For example, how to convert:
[
{
"settings": [ "master" ],
"specs": {
"hello" : {
"type" : "HelloWorldMojit"
}
}
}
]
to a YML file?
Also, when we use
$ mojito create app Hello
can't we specify that we want YML files as the default (instead of JSON files)?
Details:
I used npm's yamljs to convert the file to:
-
settings: [master]
specs: { hello: { type: HelloWorldMojit } }
and it doesn't work. And I edited it to
-
settings: [master]
specs:
hello:
type:
HelloWorldMojit
It won't work either. The server can start, but when the homepage was accessed, the error is:
error: (outputhandler.server): { [Error: Cannot expand instance [hello],
or instance.controller is undefined] code: 500 }
(the file routes.json is depending on hello being defined)
As of Mojito 0.5.2, YML is supported again. 0.5.1 and 0.5.0 do not support it.
We don't have archetypes with yaml, you will have to transform the files manually and renaming them. The good news, a more flexible archetypes infrastructure is on the making.
You should be ok with that configuration you pasted in the question, just use the latest version of mojito (0.5.x)

Resources