New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search implementation #212

Merged
merged 4 commits into from Nov 6, 2018
File filter...
Filter file types
Jump to file or symbol
Failed to load files and symbols.
+963 −15
Diff settings

Always

Just for now

Copy path View file
@@ -5,3 +5,4 @@ tmp/
build/
out/
package-lock.json
.env
Copy path View file
@@ -142,13 +142,39 @@ const handleMarkdown = (initialContent, relativePath, fileBase) => {
content = content.replace(warningMatch[0], '');
}

let rawerContent = content;

// Convert md footnotes to sidenote shortcodes
// Sidelink
content = content.replace(/([\wА-Яа-я '’“”«»]+)\[\^([^\]]+)\]/g, '{{<Sidelink "$2" "$1" />}}');
rawerContent = rawerContent.replace(/([\wА-Яа-я '’“”«»]+)\[\^([^\]]+)\]/g, '$1');

// Sidenotes Item
content = content.replace(/\n[ ]+\[\^([^\]]+)\]:((?:(?!<!--).)+)[ ]*(?:<!--\s*(.*\S)\s*-->)?/g, '\n{{<SidenotesItem id="$1" $3>}}$2{{</SidenotesItem>}}');
rawerContent = rawerContent.replace(/\n[ ]+\[\^([^\]]+)\]:((?:(?!<!--).)+)[ ]*(?:<!--\s*(.*\S)\s*-->)?/g, '\n$2');
// Sidenote
content = content.replace(/\n\[\^([^\]]+)\]:((?:(?!<!--).)+)[ ]*(?:<!--\s*(.*\S)\s*-->)?/g, '\n{{<Sidenote id="$1" $3>}}$2{{</Sidenote>}}');
rawerContent = rawerContent.replace(/\n\[\^([^\]]+)\]:((?:(?!<!--).)+)[ ]*(?:<!--\s*(.*\S)\s*-->)?/g, '\n$2');

const searchIndex = rawerContent
.replace(/\{\{((?!\}\}).)+\}\}/g, '')
.replace(/\{[\#\:][^\}]+\}/g, '')
.replace(/\n\n```((?!```)[\s\S])+\n```/g, '')
.replace(/\[([^\]]+)\]\(\)/g, '$1')
.split(/\n#+ /)
.map((cntnt, index) => {
const titleMatch = index && cntnt.match(/.+/);
const title = titleMatch ? titleMatch[0] : null;
return {
title: title,
order: index,
content: (index ? cntnt.replace(title, '') : cntnt).trim(),
}
});

if (searchIndex) {
metadata.searchIndex = searchIndex;
}

// Output metadata as json at the start of content
content = JSON.stringify(metadata) + '\n' + content;
Copy path View file
@@ -3,6 +3,8 @@ const gulp = require('gulp');
const tap = require('gulp-tap');
const rename = require('gulp-rename');

const webpack = require('webpack-stream');

const log = require('fancy-log');
const spawn = require('child_process').spawn;
const del = require('del');
@@ -65,6 +67,17 @@ const stylesSrc = () => {

const stylesFile = require('./stylesFileTask.js');

const scripts = () => {
return gulp.src('./src/js/index.js')
.pipe(webpack({
mode: 'production',
output: {
filename: 'scripts.js'
}
}))
.pipe(gulp.dest('./build/hugo/static/j/'));
}

// External tasks
const hugoBuild = () => spawn(
'hugo',
@@ -89,6 +102,7 @@ const watchEverything = () => {
gulp.watch('./src/posts/**/*', documents);
gulp.watch('./src/posts/**/examples/*.html', examples);
gulp.watch('./src/pages/**/*', pages);
gulp.watch('./src/js/**/*.js', scripts);
gulp.watch('./src/css/**/*.css', gulp.parallel(stylesFile, stylesSrc));
}

@@ -114,7 +128,7 @@ const watchReloaded = () => {

// Defining tasks
gulp.task('styles', gulp.parallel(stylesFile, stylesSrc));
gulp.task('buildForHugo', gulp.parallel(hugoSrc, pages, documents, examples, 'styles'));
gulp.task('buildForHugo', gulp.parallel(hugoSrc, pages, documents, examples, scripts, 'styles'));
gulp.task('prepareHugo', gulp.series(clean, 'buildForHugo'));
gulp.task('build', gulp.series('prepareHugo', hugoBuild));

Copy path View file
@@ -5,5 +5,8 @@
[build.environment]
HUGO_VERSION = "0.49"

[context.production]
command = "HUGO_BASEURL=$URL gulp build && npm run algolia"

[context.deploy-preview]
command = "HUGO_BASEURL=$DEPLOY_PRIME_URL gulp build"
Copy path View file
@@ -15,10 +15,12 @@
"scripts": {
"start": "gulp",
"build": "gulp build",
"algolia": "atomic-algolia",
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "MIT",
"devDependencies": {
"atomic-algolia": "^0.3.15",
"css-tree": "1.0.0-alpha.29",
"csso": "^3.5.1",
"del": "^3.0.0",
@@ -28,6 +30,7 @@
"gulp-rename": "^1.2.2",
"gulp-tap": "^1.0.1",
"shelljs": "^0.8.1",
"webpack-stream": "^5.1.1",
"yaml-front-matter": "^3.4.0"
}
}
Copy path View file
@@ -0,0 +1,109 @@
.Button {
-moz-appearance: none;
position: relative;
z-index: 1;
flex-shrink: 0;
display: inline-block;
vertical-align: baseline;
overflow: visible;
box-sizing: border-box;
max-width: 100%;
padding: 0;
border: none;
margin: 0;
border-radius: 0;
white-space: nowrap;
text-align: center;
justify-content: center;
font: inherit;
text-decoration: none;
color: inherit;
background: transparent;
cursor: pointer;
user-select: none;
--_visibility: hidden;
--_box-shadow: none;
--_Text-transform: none;
--_Text-transition: none;
}

.Button_disabled {
pointer-events: none;
}

.Button::-moz-focus-inner {
padding: 0;
border: none;
}

.Button-Content {
position: relative;
display: block;
display: inline-flex;
box-sizing: border-box;
width: 100%;
border-radius: inherit;
padding: var(--Button-padding);
}


.Button:focus {
--_visibility: inherit;
--_box-shadow: 0 0 2px 2px #6F9DEC, inset 0 0 2px 1px #6F9DEC;
}

.Button:not(:-moz-focusring):focus {
--_visibility: hidden;
}

.Button-Focus {
visibility: var(--_visibility);
position: absolute;
z-index: -1;
top: 0;
left: 0;
right: 0;
bottom: 0;
border-radius: 3px;

box-shadow: var(--_box-shadow);
}

.Button-BLHelper {
float: left;
width: 0;
min-width: 0;
}

.Button-BLHelper::before {
content: "\\a0";
}

.Button-Text {
display: block;
flex-shrink: 1;
flex-basis: 100%;
overflow: hidden;
text-overflow: ellipsis;
min-width: 0;
transition: var(--_Text-transition);
transform: var(--_Text-transform);
}

.Button-Before {
align-self: center;
flex-shrink: 0;
float: left;
}

.Button-After {
order: 1;
align-self: center;
flex-shrink: 0;
float: right;
}

.Button:focus,
.Button-Content:focus {
outline: none;
}
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.