Skip to content

Commit

Permalink
feat: add the url widget and todo editor component
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang authored Nov 25, 2023
1 parent 33e761b commit 7ebe131
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
with:
node-version: 16
- run: npm ci
# - run: npm run lint
- run: npm run eslint
29 changes: 29 additions & 0 deletions editor-components/todo/assets/decap-cms/editor-components/todo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export default {
id: 'todo',
label: 'Todo',
fields: [
{
name: 'done',
label: 'Done',
widget: 'boolean'
},
{
name: 'title',
label: 'Title',
widget: 'string'
}
],
pattern: /^-\s*\[([\sx])\]\s*(.+?)$/ms,
fromBlock: function (match) {
return {
done: match[1] === 'x',
title: match[2]
}
},
toBlock: function (data) {
return `- [${data.done ? 'x' : ' '}] ${data.title}`
},
toPreview: function (data) {
return `<p><input ${data.done ? ' checked' : ''} disabled type="checkbox">${data.title}</p>`
}
}
5 changes: 5 additions & 0 deletions editor-components/todo/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/hugomods/decap-cms/editor-components/todo

go 1.21.3

require github.com/hugomods/decap-cms v0.4.0 // indirect
2 changes: 2 additions & 0 deletions editor-components/todo/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/hugomods/decap-cms v0.4.0 h1:DGUWeog+IlQaNXsd5Vm3esoqzy/K66lpQwEVP3lT28c=
github.com/hugomods/decap-cms v0.4.0/go.mod h1:P9gUtk59PZYBCNVIqiovRPqI13WiKkutMtJl2YQLkMA=
2 changes: 2 additions & 0 deletions editor-components/todo/hugo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[[module.imports]]
path = "github.com/hugomods/decap-cms"
49 changes: 49 additions & 0 deletions widgets/url/assets/decap-cms/widgets/url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
export const name = 'url'

// eslint-disable-next-line no-undef
export const control = createClass({
handleChange: function (e) {
this.props.onChange(e.target.value)
},

render: function () {
const value = this.props.value
// eslint-disable-next-line no-undef
return h('input', {
id: this.props.forID,
className: this.props.classNameWrapper,
type: 'url',
value: value ?? '',
onChange: this.handleChange
})
},

isValid: function () {
try {
const url = new URL(this.props.value)

const protocols = this.props.field.get('protocols')
if (protocols && !protocols.includes(url.protocol)) {
return {
error: {
message: 'invalid protocol.'
}
}
}

return true
} catch (e) {
return {
error: {
message: 'invalid URL.'
}
}
}
}
})

export const schema = {
properties: {
protocols: { type: 'array' }
}
}
5 changes: 5 additions & 0 deletions widgets/url/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/hugomods/decap-cms/widgets/url

go 1.21.3

require github.com/hugomods/decap-cms v0.4.0 // indirect
2 changes: 2 additions & 0 deletions widgets/url/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/hugomods/decap-cms v0.4.0 h1:DGUWeog+IlQaNXsd5Vm3esoqzy/K66lpQwEVP3lT28c=
github.com/hugomods/decap-cms v0.4.0/go.mod h1:P9gUtk59PZYBCNVIqiovRPqI13WiKkutMtJl2YQLkMA=
2 changes: 2 additions & 0 deletions widgets/url/hugo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[[module.imports]]
path = "github.com/hugomods/decap-cms"

0 comments on commit 7ebe131

Please sign in to comment.