GatsbyJS + Netlify CMS Issue with relative path - path

I am trying to add new projects to my GatsbyJS site using Netlify CMS. The problem is that my code is using relative path to reach the thumb images but when uploading a new thumb image from netlify it saves it as an absolute path. This is causing a problem and I dont understand what it is exactly. Is Gatsby not able to read the absolute path that is being received from the CMS? If that could be the problem, how could i make that the CMS gives me a relative path?
Any help will be much appreciated :)
This is the path in my markdown files:
thumb: ../images/thumbs/memory.png
This is the path created by the CMS:
/src/images/thumbs/img_2370.jpg
This is my config.yml
backend:
name: git-gateway
branch: master # Branch to update (optional; defaults to master)
publish_mode: editorial_workflow
media_folder: "src/images/thumbs"
collections:
- name: "projects" # Used in routes, e.g., /admin/collections/blog
label: "Projects" # Used in the UI
folder: "src/projects" # The path to the folder where the documents are stored
create: true # Allow users to create new documents in this collection
slug: "{{slug}}" # Filename template, e.g., YYYY-MM-DD-title.md
fields: # The fields for each document, usually in front matter
- { label: "Title", name: "title", widget: "string" }
- { label: "Stack", name: "stack", widget: "string" }
- { label: "Slug", name: "slug", widget: "string" }
- { label: "Url", name: "url", widget: "string" }
- { label: "Publish Date", name: "date", widget: "datetime" }
- { label: "Thumb", name: "thumb", widget: "image" }
- { label: "Body", name: "body", widget: "markdown" }

This is a "known issue" that Netlify should fix soon (it has been 2 years since it has been spotted so far). Netlify doesn't support relative paths hence the image paths are broken.
Consider using the following solutions:
gatsby-plugin-netlify-cms-paths adding the following in your gatsby-config.js:
module.exports = {
plugins: [
// Including in your Gatsby plugins will transform any paths in your frontmatter
`gatsby-plugin-netlify-cms-paths`,
// Including in your Remark plugins will transform any paths in your markdown body
{
resolve: `gatsby-transformer-remark`,
options: {
plugins: [
`gatsby-plugin-netlify-cms-paths`,
],
},
},
],
}
gatsby-remark-relative-images-v2 by adding:
{
resolve: `gatsby-transformer-remark`,
options: {
plugins: [
// gatsby-remark-relative-images-v2 must
// go before gatsby-remark-images
{
resolve: `gatsby-remark-relative-images-v2`,
},
{
resolve: `gatsby-remark-images`,
options: {
// It's important to specify the maxWidth (in pixels) of
// the content container as this plugin uses this as the
// base for generating different widths of each image.
maxWidth: 590,
},
},
],
},
},
Check that media_folder and public_folder are properly configured:
media_folder: src/images/thumbs
public_folder: /images/thumbs
Note the starting slash in the public_folder and double-check that those are the correct ones.

Related

It's not possible load Highstock from the CDN as an AMD module

Expected behaviour
Hello I'd like to import Highstock lib using RequireJs AMD Module, as recommended in readme.md in github Highcharts/Highstock: GitHub Highcharts
Example to import Highchart in documentation:
require.config({
packages: [
{
name: "highcharts",
main: "highcharts",
},
],
paths: {
// Change this to your server if you do not wish to use our CDN.
highcharts: "https://code.highcharts.com",
},
});
Demos:
Import AMD Highcharts
Import AMD multiple version Highchart
Actual behaviour
If I try use highstock.js As the example below, it won´t works:
/**
* Tell RequireJS how and where to search for the highcharts package
*/
require.config({
packages: [
{
name: "highcharts",
main: "highcharts",
},
],
paths: {
highcharts: `${libPath}/highstock/9.1.2`,
},
});
define(["highcharts", "highcharts/modules/exporting", "highcharts/highcharts-more"], function (Highcharts) {
"use strict";
//highstock code here...
});
To make this work it's needed change the highstock.js file name to highcharts.js due to the name defined in lib highstock:
"highcharts/highcharts"
//Lib Highstock content
define("highcharts/highcharts", function () {
return factory(root);
});
As I can´t change the name:
{
name: "highcharts",
main: "highcharts",
}
//to
{
name: "highstock",
main: "highstock",
}
The requireJs never will find the highstock.js file, to do so, I have to change the file name to highcharts.js.
I appreciate any support.
I was calling by Highstock in wrong way:
/**
* Tell RequireJS how and where to search for the highcharts package
*/
require.config({
packages: [
{
name: "highcharts",
main: "highcharts",
},
],
The correct way to call by highstock lib is:
packages: [
{
name: "highcharts",
main: "highstock",
},

Bitbucket Failed to persist entry: API_ERROR: Branch not found

The website is built using Gatsby with Netlify CMS in Bitbucket. The error shows when I tried to change something on the custom page using the Netlify CMS (Live), but works perfectly on the local setup. This confuses me and I don't know what and why is that happening.
Here's my config.yml
backend:
name: bitbucket
repo: repo-name
branch: master
auth_type: implicit
app_id: app-id
commit_messages:
create: "Create {{collection}} “{{slug}}”"
update: "Update {{collection}} “{{slug}}”"
delete: "Delete {{collection}} “{{slug}}”"
uploadMedia: "[skip ci] Upload “{{path}}”"
deleteMedia: "[skip ci] Delete “{{path}}”"
local_backend: true
publish_mode: editorial_workflow
media_folder: static/img
public_folder: /img
(Skipped some because it is too long but here is the setup of the custom page)
- name: "pages"
label: "Pages"
label_singular: "Page"
create: true
files:
- file: "src/pages/resources/i-mop-xl-operator-resources.md"
label: "i-mop xl operator resources"
name: "i-mop xl operator resources"
fields:
- {
label: "Template Key",
name: "templateKey",
widget: "hidden",
default: "i-mop-xl-operator-resources",
}
- { label: Title, name: title, widget: string }
- { label: Heading, name: heading, widget: string }
- { label: Description, name: description, widget: string }
- {
label: "Seo Description",
name: "seodescription",
widget: "string",
}
- { label: "Seo Keyword", name: "seokeyword", widget: "string" }
- {
label: "Seo Title",
name: "seotitle",
widget: "string",
required: false,
}
And the error is saying
P.S this is only happening on the new pages that I've created.
So I've found the solution to this and I think it is pretty simple. The name should not have a blank space.
From this:
- file: "src/pages/resources/i-mop-xl-operator-resources.md"
label: "i-mop xl operator resources"
name: "i-mop xl operator resources"
To this:
- file: "src/pages/resources/i-mop-xl-operator-resources.md"
label: "i-mop xl operator resources"
name: "i-mop-xl-operator-resources"

How to iteratively expand nodes (on clicking) using popoto.js?

I am developing a web interface to the neo4j database using popoto.js. Currently, I am able to display a start node and expand the graph up to 3-4 levels by clicking on the node relationships. It seems that the underlying query that popoto uses gets updated along with the expanding graph and after a certain point the query becomes invalid and popoto resets the graph. What I am trying to create is an interface where I can expand any node in the graph (and hence expanding the overall graph) similar to what is possible in the neo4j browser. How can I achieve this?
Popoto.js handles this automatically but the schema has to be defined in the following way to assist it.
export const schema = {
Person: {
label: "Person",
value: {
name: ""
},
rel: [
{
label: "works_at",
target: {
label: "company",
},
},
{
label: "studies_at",
target: {
label: "college",
}
}
]
},
Company: {
label: "company",
value: {
name: ""
},
rel: [
{
label: "works_at",
target: {
label: "person",
},
}
]
}
}

Preloading Strategy issue for forChild routes

My application is a bit large in size. It contains many feature modules and most are lazily loaded. I want to preload a lazily loaded module, which is included in forChild routes.
For this, I have referred to Angular documentation and followed their steps. I have provided a custom preloading strategy service mentioned below.
This is my custom preloading strategy file:
#Injectable()
export class CustomPreloadingWithDelayStrategy implements PreloadingStrategy {
preload(route: Route, load: () => Observable<any>): Observable<any> {
if (route.data && route.data['preload']) {
return load();
} else {
return Observable.of(null);
}
}
}
app-routing file,
const routes: Routes =
[
XXX,
{
path: '',
data: {
base: true
},
component: MyComp,
children: [
{
path: 'page1/:id',
loadChildren: 'XXXXXXX'
},
{
path: 'page2',
loadChildren: 'XXXXXXXX'
},
{
path: 'page3',
loadChildren: 'app/feature-modules/folder1/my-folder1-module#Folder1Module'
}];
#NgModule({
imports: [RouterModule.forRoot(routes, {useHash: true, preloadingStrategy: CustomPreloadingWithDelayStrategy})],
exports: [RouterModule],
entryComponents: [ ]
})
export class AppRoutingModule {}
My Folder1Module's routing file:
const routes: Routes = [{
path: 'sub-page1/:data1/:data2',
loadChildren: 'app/feature-modules/sub-pages/pages/sub-page1.module#SubPage1Module'
}, {
path: 'sub-page2/:data1',
loadChildren: 'app/feature-modules/sub-pages/pages/sub-page2.module#SubPage2Module',
data: {preload: true}
}];
#NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class Folder1RoutingModule {
}
So when I open this route /page3/sub-page1/data1/data2, SubPage2Module is to be preloaded. But that is not happening.
I have spent nearly 2 hours to understand why the module is not pre-loaded even when I was doing everything right.
The problem lies with children, any route that is defined and further distributed with children is considered as a normal route even if you've defined your modules within the children with the help of loadChildren. The preloadingStrategy just takes modules to preload and not path/routes. The moment you've defined your routes under children it considers it as normal route and moves on to scan other routes that are provided with loadChildren. Following is the interpretation of Angular with your routes:
const routes: Routes =
[
XXX, // Normal path
{
path: '',
data: {
base: true
},
component: MyComp,
children: [ // Normal path (no module) as children is used, move on
{
path: 'page1/:id',
loadChildren: 'XXXXXXX'
},
{
path: 'page2',
loadChildren: 'XXXXXXXX'
},
{
path: 'page3',
loadChildren: 'app/feature-modules/folder1/my-folder1-module#Folder1Module'
},
],
},
{ path: 'abc', loadChildren: '../path/to/module#AbcModule', data: { preload: true }} // Module found, preload it!
];
If you debug closely in your custom CustomPreloadingWithDelayStrategy then you will observe that your route /page3/sub-page1/data1/data2 can't even make up to the route parameter of preload() method because preloading is all about loading module and not about loading routes. However, our route abc does make an appearance! Hope it helps :)

ExtJs 5 grid store/viewmodel binding: Cannot modify ext-empty-store

I'm pulling my hair out on this one...
I have a view with some grids, a store and a viewModel. I need different filtered versions of the store in different grids, so I'm trying to bind each filtered store to a grid. Now I can't even get a store to load in a grid in the first place...
Here's what my code looks like:
Store:
Ext.define('My.store.Admin.Kinder', {
extend: 'Ext.data.Store',
model: 'My.model.Kind',
storeId: 'adminKinderStore',
alias: 'store.adminKinder',
proxy: {
type: 'ajax',
method: 'post',
url: '/getKinder',
reader: {
type: 'json',
rootProperty: 'kinder'
}
}
});
ViewModel:
Ext.define('My.model.kindViewModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.kindViewModel',
requires: [
'My.model.Kind',
'My.store.Admin.Kinder'
],
view: 'kindView',
stores: {
warteliste: {
type: 'adminKinder'
}
}
});
View:
Ext.define('My.view.Admin.kinder', {
extend: 'Ext.panel.Panel',
alias: 'widget.kindView',
id: 'kinder-panel',
requires: [
'My.view.Admin.kindController',
'My.model.kindViewModel'
],
controller: 'kind',
border: false,
maxWidth: 960,
session: My.session,
viewModel: {
type: 'kindViewModel'
},
initComponent: function() {
this.activeTab = 'warteliste-tab';
this.callParent();
},
items: [
{
xtype: 'grid',
id: 'warteliste-grid',
bind: {
store: '{warteliste}'
},
border: false,
margin: '0 0 20px 0',
selModel: {
allowDeselect: true
},
columns: [
// some grid columns
],
listeners: {
afterRender: function(grid) {
grid.store.load();
}
}
}]
});
I get an error message "Cannot modify ext-empty-store", which must mean that the store is not (yet) bound when store.load() is called in the afterRender listener.
Strange thing is, when I console.log the grid, the store is there. When I console.log grid.store, an empty store is returned.
I got the same issue in afterRender event and solved it by not getting the store from the grid like
grid.store.load();
but from the ViewModel (ViewController scope):
this.getViewModel().getStore('{warteliste}').load();
Check if the store is created as expected in viewmodel. Normally, we do not have store definition files in ./store directory but we place their configurations in viewmodel.
See an example of that here: http://extjs.eu/ext-examples/#bind-grid-form - MainModel::stores
The solution to your original problem
I need different filtered versions of the store in different grids
are chained stores.
See an example of how to implement them here: http://extjs.eu/on-chained-stores/
for me it was
myGrid.getViewModel().getStore('myStoreName').load();

Resources