Skip to content

Commit

Permalink
Merge pull request #28 from ittisafur/master
Browse files Browse the repository at this point in the history
Adding a patch
  • Loading branch information
kingRayhan committed Jul 6, 2021
2 parents af162ea + 9183923 commit 679dc8a
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 21 deletions.
78 changes: 69 additions & 9 deletions dist/ghost-finder.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ghost-finder.js.map

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import GhostFinder from '../dist/ghost-finder'
new GhostFinder({
input: '#search-input',
showResult: '#search-result',
contentApiKey: '66a2f6ba7d2aeeebc1325a0625',
contentApiKey: '26d1e96d8d3b2e57a108950c06',
homeUrl: 'http://localhost:2368',
singleResultTemplate: '<li><a href="##url">##excerpt</a></li>'
})
singleResultTemplate: '<li><a href="##url">##excerpt - ##published_at</a></li>',
time_format : 'MMMM dd yyyy', // Follow line 32 in src/ghost-finder
})
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ghost-finder",
"version": "3.1.0",
"version": "3.1.1",
"description": "The most advance ghost search plugin",
"main": "dist/ghost-finder.js",
"scripts": {
Expand All @@ -14,7 +14,7 @@
},
"dependencies": {
"@tryghost/content-api": "^1.5.10",
"moment": "^2.24.0"
"date-fns": "^2.22.1"
},
"repository": {
"type": "git",
Expand All @@ -29,4 +29,4 @@
"url": "https://github.com/kingrayhan/ghost-finder/issues"
},
"homepage": "https://github.com/kingrayhan/ghost-finder#readme"
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ To see how you can get contentApiKey , [Click Here](https://github.com/kingrayha
| resultTemplate | see bellow | Result wrapper template for search result |
| singleResultTemplate | see bellow | Single search result template |
| excerpt_length | 250 | word count to show in `##excerpt` variable |
| time_format | `'MMMM Do YYYY'` | Time format string for `##published_at` variable. [Available formats](https://momentjs.com/docs/#/parsing/string-format/) |
| time_format | `'MMMM dd yyyy'` | Time format string for `##published_at` variable. [Available formats](https://date-fns.org/v2.22.1/docs/format#description) |

### Default templates

Expand Down
11 changes: 7 additions & 4 deletions src/ghost-finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import 'regenerator-runtime/runtime'
import GhostContentAPI from '@tryghost/content-api'
import moment from 'moment'
import dateFnsFormat from 'date-fns/format'

const resultDefaultTemplate = `<ul class="search-results-wrapper">
<p>Search match(es): ##resultCount</p>
Expand All @@ -28,7 +28,10 @@ class GhostFinder {
resultTemplate = resultDefaultTemplate,
singleResultTemplate = singleResultDefaultTemplate,
excerpt_length = 250,
time_format = 'MMMM Do YYYY',
/*
*time_format = 'MMMM Do YYYY',
*/
time_format = 'MMMM dd yyyy',
}) {
/**
* Chekc for errors
Expand Down Expand Up @@ -137,7 +140,7 @@ class GhostFinder {
* primary_author_avater
*/
if (post.primary_author) {
const { name, profile_image, url } = post.primary_author
const {name, profile_image, url} = post.primary_author
replacerObj['primary_author_name'] = name
replacerObj['primary_author_url'] = url
replacerObj['primary_author_avater'] = profile_image
Expand Down Expand Up @@ -166,7 +169,7 @@ class GhostFinder {
*/

if (post.published_at) {
replacerObj['published_at'] = moment(post.published_at).format(this.time_format)
replacerObj['published_at'] = dateFnsFormat(new Date(post.published_at), this.time_format)
}

/**
Expand Down

0 comments on commit 679dc8a

Please sign in to comment.