Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
slash-done
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
slash-done
Commits
5a5ba51f
Commit
5a5ba51f
authored
8 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Working v1
parent
2c33d015
No related branches found
No related tags found
1 merge request
!1
Basic plugin functionality
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+18
-0
18 additions, 0 deletions
README.md
index.js
+38
-9
38 additions, 9 deletions
index.js
package.json
+2
-1
2 additions, 1 deletion
package.json
with
58 additions
and
10 deletions
README.md
+
18
−
0
View file @
5a5ba51f
...
...
@@ -4,3 +4,21 @@ Slash command to record completed tasks as WordPress posts
## Prerequisites:
*
A WordPress site running version 4.6+ and the JSON Basic Authentication plugin
*
nginx or another proxy to front the app
## Install:
1.
`npm install`
2.
Copy
`config-sample.json`
to
`config.json`
and update to your needs
3.
`npm start`
## Usage:
1.
Make a POST request to
`/log`
with a POST body that contains the item to record
For example:
```
curl -X "POST" "http://localhost:9001/log" \
-d "I wrote a a thing!"
```
This diff is collapsed.
Click to expand it.
index.js
+
38
−
9
View file @
5a5ba51f
...
...
@@ -2,6 +2,8 @@
// Dependencies
var
express
=
require
(
'
express
'
);
var
WPAPI
=
require
(
'
wpapi
'
);
var
striptags
=
require
(
'
striptags
'
);
var
app
=
express
();
var
bodyParser
=
require
(
'
body-parser
'
);
...
...
@@ -11,24 +13,51 @@ app.use( bodyParser.urlencoded( { extended: true } ) );
// Config
var
config
=
require
(
'
./config.json
'
);
// Landing page for status checks
app
.
get
(
'
/
'
,
function
(
req
,
res
)
{
var
msg
=
'
slash-done running
'
;
var
wp
=
new
WPAPI
(
{
endpoint
:
config
.
wp_endpoint
,
username
:
config
.
wp_username
,
password
:
config
.
wp_password
}
);
res
.
send
(
msg
);
});
// Landing page for status checks
app
.
get
(
'
/
'
,
function
(
req
,
res
)
{
res
.
sendStatus
(
200
);
}
);
// Parse POST body to create WP post
app
.
post
(
'
/log
'
,
function
(
req
,
res
)
{
app
.
post
(
'
/log
'
,
function
(
req
,
res
)
{
// Don't bother if there's nothing to record
if
(
'
undefined
'
===
typeof
req
.
body
||
!
req
.
body
.
length
)
{
return
res
.
sendStatus
(
400
);
}
res
.
sendStatus
(
200
);
});
// Massage the title
var
title
=
req
.
body
;
title
=
striptags
(
title
,
[]
);
if
(
title
.
length
>
30
)
{
title
=
'
Did:
'
+
title
.
slice
(
0
,
29
);
title
+=
'
…
'
;
}
else
{
title
=
'
Did:
'
+
title
;
}
// Decorate the content
var
content
=
req
.
body
;
content
=
striptags
(
content
,
[
'
a
'
,
'
code
'
,
'
strong
'
,
'
em
'
]
);
content
=
'
<blockquote>
'
+
content
+
"
</blockquote>
\n\n
#slash-done
"
;
// Create the post
wp
.
posts
().
create
(
{
title
:
title
,
content
:
content
,
status
:
'
publish
'
}
).
then
(
function
(
resp
)
{
res
.
sendStatus
(
200
);
}
);
}
);
//tells Node which port to listen on
app
.
listen
(
config
.
node_port
,
config
.
node_listener
,
function
()
{
console
.
log
(
'
slash-done running on
'
,
config
.
node_listener
,
'
and port
'
,
config
.
node_port
);
});
}
);
This diff is collapsed.
Click to expand it.
package.json
+
2
−
1
View file @
5a5ba51f
...
...
@@ -6,7 +6,8 @@
"dependencies"
:
{
"
express
"
:
"
*
"
,
"
body-parser
"
:
"
*
"
,
"
wpapi
"
:
"
*
"
"
wpapi
"
:
"
*
"
,
"
striptags
"
:
"
*
"
},
"devDependencies"
:
{},
"scripts"
:
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment