KeystoneJS not auto-compiling LESS files to CSS - keystonejs

In KeystoneJS Docs, it mentions that upon requesting style.min.css from the server, this will compile style.less and generate style.min.css in production.
If you want Keystone to automatically compile .less files into .css files, set this value to the same path as the static option.
I have followed this and I have added some LESS code in style.less but my changes are not reflected in style.min.css, in other words, the file style.min.css is not regenerated, I am not sure if it's a bug or am I missing something.
For ease of example to reproduce, I just added this code in styles/site.less:
html {
background: black !important;
}
I expect the whole background to be black, but it's not working.
Keystone config:
let keystone = require('keystone');
keystone = keystone.init({
'mongo': process.env.MONGO_URI
'name': 'CMS',
'brand': 'CMS',
'less': 'public',
'static': 'public',
'favicon': 'public/favicon.ico',
'views': 'templates/views',
'view engine': 'pug',
'auto update': true,
'session': true,
'auth': true,
'user model': 'User',
});
keystone.import('models');
keystone.set('locals', {
_: require('lodash'),
env: keystone.get('env'),
utils: keystone.utils,
editable: keystone.content.editable,
});
keystone.set('signin logo', '../images/logo.png');
// Load your project's Routes
keystone.set('routes', require('./routes'));
// Configure the navigation bar in Keystone's Admin UI
keystone.set('nav', {
users: 'users',
intents: 'intents',
Items: ['categories', 'sub-categories', 'products'],
messages: 'messages',
});
keystone.start();

this is what i did and it works well
update generator to latest version
create new website with yo keystone
start website by using node keystone
change public/styles/site.less with changes what you did (black background)
refresh the page

Related

Vue-Cli: 'title' option for htmlWebpackPlugin does not work

I'm using vue-cli (3.4.1) and I'm trying to simply change the title of the document.
I added the following to the vue.config.js
chainWebpack: (config) => {
config
.plugin('html')
.tap((args) => {
args[0].title = 'Custom Title';
return args;
});
},
and inspected the webpack config with vue inspect --plugin html resulting in the following output
/* config.plugin('html') */
new HtmlWebpackPlugin(
{
templateParameters: function () { /* omitted long function */ },
template: '<path>\node_modules\\#vue\\cli-service\\lib\\config\\index-default.html',
title: 'Custom Title'
}
)
The title of the Webapp still says "Vue App".
Any ideas why?
PS: I do not want to set document.title = 'Custom Title' somewhere in my app. I want the title between the <title>-tags in the <head> element of the document to be altered at build time.
Unfortunately the above answers didn't help me.
As stated in the offical documentation you only need to add the vue.config.js to your root folder and add the following:
// vue.config.js
module.exports = {
chainWebpack: config => {
config
.plugin('html')
.tap(args => {
args[0].title = 'Your new title'
return args
})
}
}
Keep in mind that you have to stop the App and start again with npm run serve. This worked for me.
According to the configuration reference of the Vue CLI, you could set the title by overriding the pages section in vue.config.js. Since all config options are optional except for entry, this should do it:
module.exports = {
pages: {
index: {
entry: 'src/index/main.js',
title: 'Custom Title'
}
}
}
To set the title of a vue-cli application you can set the title in HtmlWebpackPlugin (just as you have)
/* vue.config.js */
chainWebpack: (config) => {
config
.plugin('html')
.tap((args) => {
args[0].title = 'Custom Title';
return args;
});
},
then you must edit the <title> of public/index.html to reference the title using lodash syntax.
<!-- public/index.html -->
<head>
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
Check out Html Webpack Plugin's documentation on writing your own templates!
Hope this helps!
I submitted a bug report as recommended by #tony19.
tldnr: Edit the title in the template at public/index.html which will be used at build time.
Long version: I did not have the public/index.html anymore in my project, apparently I deleted it some time ago and therefore never used the template functionality.
The cli still used a template located somewhere and therefore all changes for the htmlWebpackPlugin do nothing.
So either you disable the index.html-template and modify the htmlWebpackPlugin or you edit the template to make your changes.
I could not make changing the title from the webpack-config work, i'm assuming vue-cli overrides the one from the config later. What worked for me is setting VUE_APP_TITLE=<custom title> in .env and using <title><%= process.env.VUE_APP_TITLE %></title> in index.html. Source
You can set the title used by the HtmlWebpackPlugin by setting the "name" property in package.json in the root of your vue-cli app. No need for chainWebpack just to change the title.

Keystonejs 4.0 File system storage adapter image preview

How do I get an image preview for a Types.File field in the admin UI.
It says "The FS adapter supports all the default Keystone file schema fields. It also additionally supports and enables the filename path (required)." However when I try (doc):
format: function(item, file){
return '<img src="/files/'+file.filename+'" style="max-width: 300px">'
}
Nothing appears in the UI
The format function hasn't been working for a while as far as I can tell from the Keystone GitHub. I don't know if the function exists in Keystone 4.0. Reference here.
You could fork the current beta and patch the function yourself if you need this immediately.
You can find it at https://github.com/keystonejs/keystone/blob/v4.0.0-beta.5/fields/types/file/FileType.js#L81
Doesn't seem right to me, though. I hope they will fix it before releasing 4.0, along with the missing File Array type.
Image previews are now possible in the latest master branch of keystone (see https://github.com/keystonejs/keystone/pull/4509). At the moment you need to depend on the git version of keystone, so put this in your package.json and run npm install:
"keystone": "https://github.com/keystonejs/keystone.git"
In your model, specify thumb: true on the image field in question. You also need the url property in the schema. For example:
const storage = new keystone.Storage({
adapter: keystone.Storage.Adapters.FS,
fs: {
path: keystone.expandPath('./uploads/images'),
publicPath: '/images/'
},
schema: {
url: true,
}
})
ImageUpload.add({
name: { type: Types.Key, index: true },
image: {
type: Types.File,
storage: myStorage,
thumb: true
},
createdTimeStamp: { type: String }
});
The admin UI should now show a small preview of the image and a link to it.

gridx modules won't load in my rational/worklight environment

as i attempt to load modules with the creation of a gridx/grid, my script goes to that strange place where errors are handled by code that looks like gobbledy gook.
if i create the grid without the modules attribute the rows are displayed just fine. i am coding with worklight 6.1 in rational app developer 9.1, using dojo 1.9 that's (delivered with RAD).
my dojo includes are specified like this:
function dojoInit() {
require([ "dojo/ready", "dojo/parser", "dojox/mobile", "dojo/dom",
"dijit/registry", "dojox/mobile/ScrollableView",
"dojox/mobile/Heading", "dojox/mobile/ScrollablePane",
"dojox/mobile/Pane", "dojox/mobile/TextArea", "dojox/mobile/ContentPane",
"dojo/Deferred", "dojo/store/Memory",
"gridx/Grid", "gridx/core/model/cache/Sync", "dojox/mobile/Container",
"gridx/modules/SingleSort"],
function(ready) { ...
Here are my stylesheet links:
<link rel="stylesheet" href="css/dojo.css" />
<link rel="stylesheet" href="css/claro.css" />
<link rel="stylesheet" href="css/document.css" />
<link rel="stylesheet" href="css/Gridx.css" />
<link rel="stylesheet" href="css/Gridx_rtl.css" />
i moved the css files from gridx/resources/claro/Gridx.css and other locations within the dojo toolkit library to a known relative location, temporarily, in order to eliminate the possibility that the css files could not be resolved. and i am specifying just the 'claro' class in the div wherein this grid is placed. there is no difference in the behavior of the grid in either case.
My grid is created like this:
toStore=new dojo.store.Memory({ idProperty: 'PICYNO', data: resultSet });
toColumns=[
{ id: 'PICYNO', field: 'PICYNO', name: 'Cycle' , width: '80px' , editable: true },
{ id: 'PIDSC1', field: 'PIDSC1', name: 'Description' , width: '300px', editable: true },
{ id: 'PICYCS', field: 'PICYCS', name: 'Status' , width: '60px' , editable: true },
{ id: 'PPICSDJ',field: 'PPICSDJ', name: 'Date' , width: '80px' , editable: true },
{ id: 'PICYIT', field: 'PICYIT', name: 'Items' , width: '60px' , editable: true },
{ id: 'PICYLO', field: 'PICYLO', name: 'Locations' , width: '60px' , editable: true }
];
var cacheClass = "gridx/core/model/cache/Sync";
var tsGrid = new gridx.Grid({
id: 'idHeaderGrid',
cacheClass: cacheClass,
store: toStore,
// modules:[modules.SingleSort, modules.SelectRow],
// modules:[gridx.modules.SingleSort],
// modules:[gridx/modules/SingleSort],
// modules: [ SingleSort ],
// modules: [ Sort ],
structure: toColumns
});
tsGrid.placeAt('idGridContentPane');
tsGrid.startup();
if i comment all the lines that specifiy 'modules:' as you see, then the grid is displayed (but it's ugly, as if the stylesheets weren't applied at all.)
if i try any variation of specifying the standard sort module, this function will tank. i know it's probably because i'm not specifying my environment correctly, but i can't see how.
Any known problems with any of the versions that i'm using? any suggestion is appreciated.
--------- Updated ------------
I have progressed to the extent that i can display a grid, but the formatting is still off.
Based on the results of experimenting with a non-worklight project where i was able to materialize the grid with modules, and also realizing that with either type of project (web or worklight), i was able to resolve dojo and Gridx objects even though the javascript resources are configured differently, i decided to try a local require statement to specify the dojo modules in the immediate context and it worked. The original dojo configuration in worklight was ocnfigured in the main.js object that's automatically generated with a worklight application. it looked like this:
function wlCommonInit() {
require([ "layers/core-web-layer", "layers/mobile-ui-layer" ], dojoInit);
}
function dojoInit() {
require([ "dojo/ready", "dojo/parser", "dojox/mobile", "dojo/dom",
"dijit/registry", "dojox/mobile/ScrollableView",
"dojox/mobile/Heading", "dojox/mobile/ScrollablePane",
"dojox/mobile/Pane", "dojox/mobile/TextArea", "dojox/mobile/ContentPane",
"dojo/Deferred", "dojo/store/Memory", "dojox/mobile/Container",
"gridx/modules/SingleSort", "gridx/modules/ColumnResizer", "gridx/modules/RowHeader"
],
function(ready) {
ready(function() {
ccInit();
});
});
}
I removed the module declarations from the main.js and added them in the ccInit.js application where the grid is created, like this:
function populateGrid() {
require([
'dojo/store/Memory',
'gridx/Grid',
'gridx/core/model/cache/Sync',
'gridx/modules/SingleSort',
'gridx/modules/ColumnResizer',
'gridx/modules/RowHeader'
], function(Store, Grid, Cache, Sort, ColumnResizer, RowHeader) {
. . .
var tsGrid = new gridx.Grid({
id: 'idHeaderGrid',
cacheClass: Cache,
store: toStore,
modules: [ Sort, ColumnResizer, RowHeader ],
structure: toColumns,
selectRowTriggerOnCell: true
});
...
The grid is created successfully when it is created within an immediate require context as shown. Lots of dojo calls and even a grid without modules will work if i use the non-immediate approach.
The syles are still messed up, though. Column headings are blank and the table looks nothing like a claro-styled grid. I am sure that i have set up the css includes in the html header correctly (using my working web project as a model). Is there some worklight initialization or 'skin' overlay that's messing this up?
Thanks for any comment.
--- workaround is to refer to all classes, locally.
I solved the problem with stylesheets by creating the gridx.css in the common\css folder, then I edited it by replacing each #import with a copy/paste of the imported css source. So my gridx.css is a merge of all the source code from all the imports. i point to that css\gridx in my header link and i get reasonable results.
So in summary, i had to explicitly require the gridx classes in the custom function rather than in the dojo require statement in the main.js. And i had to merge all of the gridx styles and refer to them locally as well. The problem where gridx.css and other style sheets are not resolved through relative path includes that point to the dojo toolkit seems like a bug. Those stylesheets seem to be loaded in the run-time-generated server as evidenced by the console messages that look like this:
Failed to load resource: the server responded with a status of 404 (Not Found) http://myWLdevServer.mycomputer.local:10080/JustGridx/apps/services/preview/JustGridx/common/0/default/dojo/gridx/resources/claro/Gridx.css
If a developer is supposed to do some kind of server config to point to those CSS files, then I'm not seeing it.
I am leaving this post as unsolved in case someone agrees with me that this is a bug at worst or is not intuitive and should be documented at best.
From the comments by user3208130:
Sorry for not following up for all this time. i did finally work
around the problem by not importing anything. I copied the main
gridx.css from gridx\resources into my project, and then for each of
the imports listed in that file, i copy/pasted the source from the
various locations within the gridx collection as well as all of the
claro css files since gridx only uses that font. i had to turn off
theme switching depending on the device since claro looks awful on
windows8 and android otherwise.
I know this makes no sense, but i tried every variation of relative and explicit path that i could imagine for the import
statements in both of the html header and within the main css files
and nothing else worked. i suspected that the css files are not copied
automatically when device environments are created but i couldn't
prove that.

Dojo amd loading cross-domain modules at runtime

I want to load Dojo1.9 amd modules from an ad-hoc server on the www, but I won't know from where until runtime (with url params).
In essence, I want to do the equivalent of this:
require(['http://www.foo.com/SomeRandomModule'], function( SomeRandomModule ) {
// use SomeRandomModule
});
Quick and dirty way
Might have some unexpected quirks when it comes to the module system and relative paths, I haven't used it enough to say:
require([ "//host/myext/mod1/mod2.js" ],function(mod2){
// If current webpage is http:// or https:// or file://
// it tries to use the same protocol
});
Better way
Configure require() to treat all modules that start with a certain package name (e.g. foo) as coming from a particular URL. From your starter page, something like:
<script src="dojo/dojo.js"
data-dojo-config="packages:[{name:'myext',location:'//host/js/myext'}], async: 1, >
</script>
This lets you vastly improve your first example to:
require([ "myext/mod1/mod2" ],function(mod2){
});
If you are using a Dojo Bootstrap installation instead, you can avoid touching your data-dojo-config and instead put it inside the run.js startup file:
require({
baseUrl: '',
packages: [
'dojo',
'dijit',
'dojox',
'myapp',
{ name: 'myext', location: '//host/js/myext', map: {} }
]
}, [ 'myapp' ]);

flowplayer streaming mp4 from apache

I'm having some problems getting this to work. I think I've done it right based on http://flowplayer.org/forum/5/14664#post-14830). The clip starts to play fine, but when I skip to a part of the clip which hasn't loaded yet it just goes back to the start of the file/video
Sadly the browser used is IE6 for the most part :(
Apache 2 running on Redhat
I've created an mp4 file with ffmpeg.
Run qt-faststart 1.mp4 1.qt.mp4
Installed mod_flvx.c
Added:
LoadModule flvx_module modules/mod_flvx.so
AddHandler flv-stream .flv
To Apache httpd.conf
Using the example page:
<script type="text/javascript">
flowplayer("player", "flash/flowplayer-3.0.3.swf", {
clip: {
url: 'http://servername/player/media/1.qt.mp4',
// default provider: 'h264streaming'
provider: flashembed.isSupported([9, 115]) ? 'h264streaming' : 'lighttpd',
scaling: 'fit',
autoBuffering: true,
autoplay: false,
bufferLength: 3
},
log: {
level: 'debug'
},
plugins: {
h264streaming: {
url: 'flash/flowplayer.h264streaming-3.0.5.swf'
},
controls: {
url: 'flash/flowplayer.controls-3.0.3.swf',
// which buttons are visible and which not ?
play:false,
fullscreen:true,
// scrubber is a well known nickname to the timeline/playhead combination
scrubber: true
}
}
});
</script>
Anyone have any suggestions?
Thanks
First off, you need to see if your apache is configured to correctly seek to parts of the video. You can do that by passing a get parameter like my_vide_path.mp4?start=10 to have it start 10 seconds in. If it successfully starts 10 seconds in, then apache is set up correctly and you need to make flowplayer work. If apache isn't set up correctly, then even the correct flowplayer config won't help.
I doubt your apache is set up correctly though. You're telling apache to handle .flv files and yet you're using mp4s.
I've successfully gotten this to work with the apache module from http://h264.code-shop.com/trac/wiki.
You'll need to add and load the module into apache and tell apache to handle .mp4 files with it.
Next step would be to test with that get parameter ?start=10 to see if it is seeking correctly.
After that, all you need to do is:
<script type="text/javascript">
flowplayer("player", "flash/flowplayer-3.0.3.swf", {
clip: {
url: 'http://servername/player/media/1.qt.mp4',
default provider: 'h264streaming'
},
plugins: {
h264streaming: {
url: 'flash/flowplayer.h264streaming-3.0.5.swf'
}
}
});
</script>
I used the updated flowplayer swf and instead of h264's swf, the flowplayer plugin for psuedostreaming, as it works with the newer version of flowplayer and apparently the h264 one didnt.