Collections in Hugo data file using Netlify CMS - netlify

I'm trying to get my head round using Netlify CMS with Hugo ssg.
I use:
netlify-cms#1.0
hugo#0.29
I have a simple netlify-cms config.yml with two collections: posts and authors.
backend:
name: github
repo: sebhewelt/atlas
branch: master
display_url: https://mypage.com
publish_mode: editorial_workflow
media_folder: "static/uploads"
public_folder: "/uploads"
collections:
- label: "Posts"
name: "post"
folder: "content"
create: true
slug: "{{year}}-{{month}}-{{day}}-{{slug}}"
fields:
- { label: "Title", name: "title", widget: "string" }
- { label: "Publish Date", name: "date", widget: "datetime" , format: "YYYY-MM-DD hh:mma"}
- { label: "Body", name: "body", widget: "markdown" }
- label: "Authors"
name: "author"
folder: "data"
create: true
fields:
- {label: "Name", name: "name", widget: "string"}
- {label: "About", name: "about", widget: "string"}
The docs distinguish two collection types, of which I assume i should choose file collection, as I'd like to hold the authors data in one file.
I'd like to be able to add authors via admin dashboard and save it to file in data folder. The docs doesn't provide an example of how should the file holding the authors look like (Or does the cms make it automatically?).
I encounter an error with my current config. When I'm saving the "New Author" i get this:
Failed to persist entry: Error: Collection must have a field name that
is a valid entry identifier
Why do i get this error?

Your authors file needs to be under a top-level collection. Also, if you want to be able to add multiple authors to the file, you need to wrap the "name" and "about" widgets in a "list" type widget.
Example:
collections:
- label: "Settings"
name: "settings"
files:
- name: "authors"
label: "Authors"
file: "data/authors.yml"
extension: "yml"
fields:
- label: "Author"
name: "author"
widget: "list"
fields:
- {label: "Name", name: "name", widget: "string"}
- {label: "About", name: "about", widget: "string"}
CMS docs for file collections: https://www.netlifycms.org/docs/collection-types/#file-collections
CMS docs for list widgets: https://www.netlifycms.org/docs/widgets/#list

Related

How to edit Hugo content files directly in content root folder

I am new to netlify and netlifyCMS. Did upload a Hugo site which is working well. Now trying to implement CMS. It is a very simple site with only a few *.md content files located directly in the root of the /content folder. How do I need to configure the config.yml so that I can edit them? I did only find how to edit collections in subfolders of /content or single files.
Thank you
Best regards
I think I did find a solution. Did add every content-file as a single file.
collections: # A list of collections the CMS should be able to edit
- label: "Inhalt"
name: "inhalt"
files:
- label: "Home"
name: "home"
file: "/content/home.md"
fields: # The fields each document in this collection have
- {label: "Title", name: "title", widget: "string"}
- {label: "Body", name: "body", widget: "markdown"}
- label: "TCM"
name: "tcm"
file: "/content/tcm.md"
fields: # The fields each document in this collection have
- {label: "Title", name: "title", widget: "string"}
- {label: "Body", name: "body", widget: "markdown"}
- label: "Psycho"
name: "psycho"
file: "/content/psycho.md"
fields: # The fields each document in this collection have
- {label: "Title", name: "title", widget: "string"}
- {label: "Body", name: "body", widget: "markdown"}

Is there any way to exclude null properties when using Groovy's YAMLBuilder?

I'm using Groovy to generate an openapi spec document in YAML. I'm using YamlBuilder to convert the object model to a YAML string.
It's been working well so far, but one issue I've noticed is that null properties are present in the YAML output. This is causing validation errors in the openapi validators I'm using, so I'd like to remove any null properties from the YAML output.
Is there any way to achieve this? I can't see it in the docs. The equivalent JSONBuilder allows config options to be set, is there such a thing for YamlBuilder?
The part of the script which generates the YAML looks like this:
def generateSpec() {
println "============================\nGenerating Customer SPI spec\n============================"
def components = generateComponents()
def paths = generatePaths()
def info = Info
.builder()
.title('Customer SPI')
.description('A customer API')
.version('0.1')
.build()
def customerSpec = [openapi: "3.0.3", components : components, info : info, paths : paths]
def yaml = new YamlBuilder()
yaml(customerSpec)
println(yaml.toString())
return yaml.toString()
}
Here's my current output. Note the null value of the format property on firstname, among others.
---
openapi: "3.0.3"
components:
schemas:
Customer:
type: "object"
properties:
firstname:
type: "string"
format: null
ArrayOfCustomers:
items:
$ref: "#/components/schemas/Customer"
info:
title: "Customer SPI"
version: "0.1"
description: "An API."
paths:
/customers:
parameters: null
get:
responses:
"200":
content:
application/json:
schema:
$ref: "#/components/schemas/ArrayOfCustomers"
description: "An array of customers matching the search criteria"
summary: "Search customers"
/customers/{customerRef}:
parameters:
- required: true
schema:
type: "string"
format: null
description: "Customer reference"
in: "path"
name: "customerRef"
get:
responses:
"200":
content:
application/json:
schema:
$ref: "#/components/schemas/Customer"
description: "A customer with the given reference"
summary: "Load a customer"

Get the list of records to which a file is Attached

I want to get the list of all the records(whether it may be entity record, transaction record or any other record) to which a single file is attached from the file cabinet in Netsuite. Is there any way to do so??
I believe the saved search approach is the best way. But I don't think you can do it by creating a Document saved search. I think you have to create an entity saved search, a transaction saved search, etc, and then put in the file ID into the criteria filter's "File fields..." internal ID field.
Having to create a saved search for each record type is a bit clunky, but if you have SuiteScript experience it helps if you have the "NetSuite: Search Export" chrome extension. You can create one saved search on the front-end and then use that extension to "Export as script" the one saved search and try to reproduce its criteria for each record type that you are interested in linking to the one file.
Let suppose you want to search a file for a Salesorder. You need to do it separate for entity, transaction etc, remove type and id for all records search.
Here is an example in 2.0.
var salesorderSearchObj = search.create({
type: "salesorder",
filters:
[
["type","anyof","SalesOrd"],
"AND",
["internalid","anyof",12345],
"AND",
["taxline","is","F"],
"AND",
["cogs","is","F"],
"AND",
["shipping","is","F"],
"AND",
["mainline","is","T"]
],
columns:
[
search.createColumn({
name: "trandate",
sort: search.Sort.ASC,
label: "Date"
}),
search.createColumn({
name: "internalid",
join: "file",
label: "Internal ID"
}),
search.createColumn({
name: "url",
join: "file",
label: "URL"
}),
search.createColumn({
name: "url",
join: "lineFile",
label: "URL"
})
]
});
var searchResultCount = salesorderSearchObj.runPaged().count;
salesorderSearchObj.run().each(function(result){
var fileId = result.getValue({
name: "internalid",
join: "file",
label: "Internal ID"
});
var fileObj = file.load({id: fileId});
return true;
});

How to search cases by CompanyId in Netsuite Suitescript 2.0?

I can able to search the case by company name
var mySearch = search.create({
type: search.Type.SUPPORT_CASE,
columns: [{
name: 'title'
}, {
name: 'company'
}],
filters: [{
name: 'company',
operator: 'is',
values: 'Test'
}]
});
return mySearch.run({
ld: mySearch.id
}).getRange({
start: 0,
end: 1000
});
But I am not able to search case by company id.
companyId is 115
Below are not working
i)
filters: [{
name: 'company',
operator: 'is',
values: 115
}]
ii)
filters: [{
name: 'companyid',
operator: 'is',
values: 115
}]
According to the Case schema company is a Text filter, meaning you would have to provide it with the precise Name of the company, not the internal ID.
Instead you may want to use the customer.internalid joined filter to provide the internal ID. Also, Internal ID fields are nearly always Select fields, meaning they do not accept the is operator, but instead require the anyof or noneof operator.
You can find the valid operators by field type on the Help page titled Search Operators
First, you can try this :
var supportcaseSearchObj = search.create({
type: "supportcase",
filters:
[
["company.internalid","anyof","100"]
],
columns:
[
search.createColumn({
name: "casenumber",
sort: search.Sort.ASC
}),
"title",
"company",
"contact",
"stage",
"status",
"profile",
"startdate",
"createddate",
"category",
"assigned",
"priority"
]
});
Second : how did I get this ? The answer is hint that will make your life easier :
Install the "NetSuite Saved Search Code Export" chrome plugin.
In Netsuite UI, create your saved search (it is always easier that doing it in code).
After saving the search, open it again for edition.
At the top right corner (near list, search menu in the netsuite page), you will see a link "Export as script" : click on it and you will get your code ;)
If you can not install the chrome plugin :
In Netsuite UI, create your saved search (it is always easier that doing it in code).
In your code, load your saved search
Add a log.debug to show the [loadedesearchVar].filters
You can then copy what you will see in the log to use it as your search filters.
Good luck!

Add widget without it showing up in Netlify CMS preview

Is there a backend widget type which allows the user to enter a text value, in the editor but not displayed in the preview to the right?
I have this configuration from the example out of the box:
- label: "Blog"
name: "blog"
folder: "_posts/blog"
create: true
fields:
- {label: "Title", name: "title", widget: "string"}
- {label: "Publish Date", name: "date", widget: "datetime"}
- {label: "Featured Image", name: "thumbnail", widget: "image"}
- {label: "Body", name: "body", widget: "markdown"}
I do not want the publish date to show up in the preview.
Netlify CMS allows for the preview to be custom and include or exclude anything you would like in the preview. Mimic your page layout and use the style sheet from your build to give a WYSIWYG layout.
Click here for Custom Preview Template docs
You might have something like the following in your index.html in the CMS folder
<script>
var PostPreview = createClass({
render: function() {
var entry = this.props.entry;
var image = entry.getIn(['data', 'thumbnail']);
var imageContainer = (image) ? h('section', {className: "mdc-card__media", style: {backgroundImage: `url(${image})`, height: '20rem'}},) : h('div');
return h('div', {},
h('div', { className: "blog-post" },
imageContainer,
h('div', { },
h('h1', { },
h('span', { }, entry.getIn(['data', 'title']))
),
),
h('div', {className: "post-body"},
h('div', { }, this.props.widgetFor('body'))
)
)
)
}
});
CMS.registerPreviewTemplate("blog", PostPreview);
</script>
Make sure to include the script above AFTER the cms.js script link

Resources