Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
gmfmi committed May 28, 2020
1 parent b5a6ff6 commit 92f4767
Show file tree
Hide file tree
Showing 15 changed files with 5,862 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Gm Fmi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# searchinghost-easy
Beautiful search bars made accessible to anyone
# SearchinGhost Easy

Beautiful search bars made accessible to any Ghost CMS user
2 changes: 2 additions & 0 deletions dist/searchinghost-easy-backpack.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dist/searchinghost-easy-basic.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions docs/backpack/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>"Backpack" theme | SearchinGhost Easy</title>
<style>
.main {
height: 3000px;
text-align: center;
padding-top: 5em;
}
</style>
</head>
<body>

<div class="main">
<a href="#searchinghost-easy">Open Search Box</a>
</div>

<script src="https://cdn.jsdelivr.net/gh/gmfmi/searchinghost-easy@0.1.0/dist/searchinghost-easy-backpack.js"></script>
<!-- <script src="../../dist/searchinghost-easy-backpack.js"></script> -->
<script>
new SearchinGhostEasy({
contentApiKey: '22444f78447824223cefc48062',
apiUrl: 'https://demo.ghost.io'
});
</script>

</body>
</html>
35 changes: 35 additions & 0 deletions docs/basic/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>"Basic" theme | SearchinGhost Easy</title>
<style>
.main {
height: 3000px;
text-align: center;
padding-top: 5em;
}
</style>
</head>
<body>

<div class="main">
<a href="#searchinghost-easy">Open Search Box</a>
</div>

<script src="https://cdn.jsdelivr.net/gh/gmfmi/searchinghost-easy@0.1.0/dist/searchinghost-easy-basic.js"></script>
<!-- <script src="../../dist/searchinghost-easy-basic.js"></script> -->
<script>
new SearchinGhostEasy({
contentApiKey: '22444f78447824223cefc48062',
apiUrl: 'https://demo.ghost.io',
searchEngineOptions: {
template: (post) => `<a href="${post.url}">${post.published_at} - ${post.title}</a>`,
debug: true
}
});
</script>

</body>
</html>
67 changes: 67 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const pkg = require('./package.json');
const { src, dest, series, watch } = require('gulp');
const flatmap = require('gulp-flatmap');
const del = require('delete');
const rename = require("gulp-rename");
const htmlmin = require('gulp-htmlmin');
const webpack = require('webpack-stream');
const header = require('gulp-header');
const replace = require('gulp-replace');

let isProduction = true;

function clean(cb) {
del('dist/**', cb);
}

/**
* This is a tricky one.
* First we iterate over the theme template to load them in memory,
* then, we start from 'searchinghost-easy.js' and replace the HTML into
* the getHtmlTemplate() function. That's why we need 'flatmap'.
*/
function generate(cb) {
return src('themes/**/*.html')
.pipe(htmlmin({
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
removeComments: true,
removeAttributeQuotes: true,
minifyCSS: true,
minifyJS: true
}))
.pipe(flatmap(function(stream, file){
let name = file.path.split(/[\\/]/).pop().split('.').shift();
let htmlContent = file.contents.toString().replace(/"/g, '\\"');
return src('src/searchinghost-easy.js')
.pipe(webpack({
mode: 'production',
output: {
filename: `${name}.js`,
library: 'SearchinGhostEasy',
libraryExport: 'default',
},
optimization: {
minimize: isProduction
}
}))
.pipe(replace('{{HTML_TEMPLATE}}', htmlContent));
}))
.pipe(rename({ prefix: "searchinghost-easy-", extname: '.js' }))
.pipe(header(`/*! searchinghost-easy v${pkg.version} (${pkg.homepage}) license ${pkg.license} */\n`))
.pipe(dest('dist'));
}

function build() {
isProduction = true;
return series(clean, generate);
}

function watchFiles() {
isProduction = false;
watch(['themes/**/*.html', 'src/searchinghost-easy.js'], { ignoreInitial: false }, generate);
}

exports.default = build();
exports.build = build();
exports.watch = watchFiles;
Loading

0 comments on commit 92f4767

Please sign in to comment.