Skip to content

Commit e59d132

Browse files
committed
feat(website): ensure the inputs are mandatory
Move the forms to a partial (had a hard time with HAML-based partials...) Small box-shadow if not specified Add a "I'm the owner of that website" checkbox
1 parent 6c7335c commit e59d132

7 files changed

Lines changed: 89 additions & 57 deletions

File tree

docs/Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ source 'https://rubygems.org'
55

66
group :development, :test do
77
gem 'jekyll', '< 3'
8-
gem 'haml'
8+
gem 'jekyll-haml'
99
gem 'rouge'
1010
gem 'sass'
1111
gem 'guard'

docs/Gemfile.lock

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ GEM
6767
jekyll
6868
jekyll-gist (1.4.0)
6969
octokit (~> 4.2)
70+
jekyll-haml (0.1.3)
71+
haml (>= 3.0.0)
72+
jekyll (>= 0.10.0)
7073
jekyll-paginate (1.1.0)
7174
jekyll-sass-converter (1.3.0)
7275
sass (~> 3.2)
@@ -127,9 +130,9 @@ DEPENDENCIES
127130
guard-bundler
128131
guard-jekyll-plus
129132
guard-livereload
130-
haml
131133
jekyll (< 3)
132134
jekyll-contentblocks
135+
jekyll-haml
133136
nokogiri
134137
rouge
135138
sass

docs/_includes/join-form.haml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
%form.join-form{action: '#', method: 'POST'}
2+
%h3 Get Started. It’s FREE!
3+
.spacer20
4+
.input-group
5+
%span.input-group-addon
6+
%i.fa.fa-fw.fa-globe
7+
%input.form-control{type: 'text', placeholder: 'https://website.com/doc', name: 'url'}
8+
%p.text-sm We’ll crawl the <u>documentation pages</u> of your website and index them on Algolia.
9+
.spacer10
10+
.input-group
11+
%span.input-group-addon
12+
%i.fa.fa-fw.fa-envelope-o
13+
%input.form-control{type: 'email', placeholder: 'you@example.org', name: 'email'}
14+
%p.text-sm We’ll email you the code you need to integrate the search into your documentation.
15+
%p.checkbox.text-center
16+
%label
17+
%input{type: 'checkbox', name: 'owner'}
18+
%span I'm the <u>owner</u> of that website
19+
.spacer20
20+
.text-center
21+
%button.btn.btn-primary.btn-lg{type: 'submit'}
22+
JOIN THE BETA!

docs/_plugins/haml.rb

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
1+
require 'jekyll-haml'
2+
13
module Jekyll
2-
class HamlConverter < Converter
3-
safe true
4-
5-
def setup
6-
return if @setup
7-
require 'haml'
8-
@setup = true
9-
rescue
10-
STDERR.puts 'do `gem install haml`'
11-
raise FatalException.new("Missing dependency: haml")
12-
end
134

14-
def matches(ext)
15-
ext =~ /haml/i
5+
class HamlPartialTag < Liquid::Tag
6+
def initialize(tag_name, file, tokens)
7+
super
8+
@file = file.strip
169
end
1710

18-
def output_ext(ext)
19-
".html"
20-
end
11+
def render(context)
12+
includes_dir = File.join(context.registers[:site].source, '_includes')
13+
14+
if File.symlink?(includes_dir)
15+
return "Includes directory '#{includes_dir}' cannot be a symlink"
16+
end
2117

22-
def convert(content)
23-
setup
24-
engine = Haml::Engine.new(content)
25-
engine.render
18+
if @file !~ /^[a-zA-Z0-9_\/\.-]+$/ || @file =~ /\.\// || @file =~ /\/\./
19+
return "Include file '#{@file}' contains invalid characters or sequences"
20+
end
21+
22+
return "File must have \".haml\" extension" if @file !~ /\.haml$/
23+
24+
Dir.chdir(includes_dir) do
25+
choices = Dir['**/*'].reject { |x| File.symlink?(x) }
26+
if choices.include?(@file)
27+
source = File.read(@file)
28+
conversion = ::Haml::Engine.new(source).render
29+
partial = Liquid::Template.parse(conversion)
30+
return partial.render!(context).gsub(/\s+/, ' ')
31+
else
32+
"Included file '#{@file}' not found in _includes directory"
33+
end
34+
end
2635
end
2736
end
37+
2838
end
39+
40+
Liquid::Template.register_tag('haml', Jekyll::HamlPartialTag)

docs/css/_home.scss

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,19 @@ html, body {
129129
letter-spacing: 2px;
130130
font-weight: bold;
131131
}
132+
.input-group, .checkbox input {
133+
&.has-errors {
134+
-webkit-box-shadow: 0px 0px 20px 0px #FF2E6C;
135+
-moz-box-shadow: 0px 0px 20px 0px #FF2E6C;
136+
box-shadow: 0px 0px 20px 0px #FF2E6C;
137+
}
138+
}
132139
}
133140

134141
@media (min-width: 1200px) {
135142
.jumbotron .join-form {
136143
position: absolute;
137-
top: 200px;
144+
top: 170px;
138145
right: 120px;
139146
padding: 10px 40px 30px;
140147
}

docs/index.haml

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,8 @@ layout: default
1616
.text-center
1717
%p We’ve created the fastest, easiest way to search within documentation.
1818
%p
 And best of all? It’s FREE.
19-
%form.join-form{action: '#', method: 'POST'}
20-
%h3 Get Started. It’s FREE!
21-
.spacer20
22-
.input-group
23-
%span.input-group-addon
24-
%i.fa.fa-fw.fa-envelope-o
25-
%input.form-control{type: 'email', placeholder: 'you@example.org', name: 'email'}
26-
%p.text-sm We’ll email you the code you need to integrate the search into your documentation.
27-
.spacer20
28-
.input-group
29-
%span.input-group-addon
30-
%i.fa.fa-fw.fa-globe
31-
%input.form-control{type: 'text', placeholder: 'https://website.com/doc', name: 'url'}
32-
%p.text-sm We’ll crawl the documentation pages of your website and index them on Algolia.
33-
.spacer20
34-
.text-center
35-
%button.btn.btn-primary.btn-lg{type: 'submit'}
36-
JOIN THE BETA!
19+
20+
{% haml join-form.haml %}
3721
#section_why.page-section
3822
.m800.m-l-r-auto
3923
%h2.page-section-title Why DocSearch?
@@ -128,22 +112,8 @@ layout: default
128112
%p We’ll get back to you within a few hours with everything you need to integrate your new search into your website.
129113
%p Oh, and did we mention it's FREE? No commitment. No subscription. Everything is on us!
130114
.spacer30
131-
%form.join-form{action: '#', method: 'POST'}
132-
.input-group
133-
%span.input-group-addon
134-
%i.fa.fa-fw.fa-envelope-o
135-
%input.form-control{type: 'email', placeholder: 'you@example.org', name: 'email'}
136-
%p.text-sm We’ll email you the code you need to integrate the search into your documentation.
137-
.spacer20
138-
.input-group
139-
%span.input-group-addon
140-
%i.fa.fa-fw.fa-globe
141-
%input.form-control{type: 'text', placeholder: 'https://website.com/doc', name: 'url'}
142-
%p.text-sm We’ll crawl the documentation pages of your website and index them on Algolia.
143-
.spacer20
144-
.text-center
145-
%button.btn.btn-primary.btn-lg{type: 'submit'}
146-
JOIN THE BETA!
115+
116+
{% haml join-form.haml %}
147117

148118
{% contentfor site-footer %}
149119
<script src="{{ "/js/home.js" | prepend: site.baseurl }}"></script>

docs/js/home.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@
33
var $button = $(this).find('button');
44
var $email = $(this).find('input[name="email"]');
55
var $url = $(this).find('input[name="url"]');
6+
var $owner = $(this).find('input[name="owner"]');
7+
var error = false;
8+
$(this).find('.has-errors').removeClass('has-errors');
9+
if (!$email.val()) {
10+
$email.closest('.input-group').addClass('has-errors');
11+
error = true;
12+
}
13+
if (!$url.val()) {
14+
$url.closest('.input-group').addClass('has-errors');
15+
error = true;
16+
}
17+
if (!$owner.is(':checked')) {
18+
$owner.addClass('has-errors');
19+
error = true;
20+
}
21+
if (error) {
22+
return false;
23+
}
624
$button.attr('disabled', true);
725
$.ajax({
826
url: 'https://www.algolia.com/docsearch/join',

0 commit comments

Comments
 (0)