madness 0.7.6 → 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +64 -73
- data/app/public/css/main.css +2 -1
- data/app/public/css/main.css.map +1 -1
- data/app/styles/_nav.scss +2 -2
- data/lib/madness.rb +4 -1
- data/lib/madness/breadcrumbs.rb +1 -1
- data/lib/madness/command_line.rb +10 -5
- data/lib/madness/directory.rb +1 -1
- data/lib/madness/docopt.txt +17 -4
- data/lib/madness/document.rb +37 -7
- data/lib/madness/item.rb +2 -2
- data/lib/madness/navigation.rb +1 -1
- data/lib/madness/refinements/string_refinements.rb +6 -0
- data/lib/madness/search.rb +6 -2
- data/lib/madness/server.rb +5 -1
- data/lib/madness/server_base.rb +18 -7
- data/lib/madness/settings.rb +7 -3
- data/lib/madness/static.rb +2 -2
- data/lib/madness/table_of_contents.rb +3 -3
- data/lib/madness/templates/madness.yml +6 -3
- data/lib/madness/version.rb +1 -1
- metadata +22 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe93b51cce9d5f1e2b37597b86bbcab62273fd2ba588d013308b194bb607d20e
|
4
|
+
data.tar.gz: 4b5e8a9de2af92f7aef8fa86792c8f3156ae9aba4b5049507693c2467dcc439c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78e416333ece7eb2a236a07593c31f78cb93919f8842b5fede75baff6ae6e07d956ff0b1f30501c1be99416aab4ce036885d49800eeea5d38d5f811745d4c55d
|
7
|
+
data.tar.gz: d237b707b9a7d7a6d9334942a760811f51463a9aa04c007f54789bfa89be08cd04ac6bf7e6f946d86aa45302b50d3d6e4e7c5d4d83ffec88fb4a42c65cdb063c
|
data/README.md
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
Madness - Instant Markdown Server
|
2
|
-
==================================================
|
1
|
+
# Madness - Instant Markdown Server
|
3
2
|
|
4
3
|
[![Gem Version](https://badge.fury.io/rb/madness.svg)](https://badge.fury.io/rb/madness)
|
5
|
-
[![Build Status](https://
|
4
|
+
[![Build Status](https://github.com/DannyBen/madness/workflows/Test/badge.svg)](https://github.com/DannyBen/madness/actions?query=workflow%3ATest)
|
6
5
|
[![Maintainability](https://api.codeclimate.com/v1/badges/fa440dc4dbf895734d74/maintainability)](https://codeclimate.com/github/DannyBen/madness/maintainability)
|
7
6
|
|
8
7
|
---
|
9
8
|
|
10
|
-
Screenshots (click to zoom)
|
11
|
-
--------------------------------------------------
|
9
|
+
## Screenshots (click to zoom)
|
12
10
|
|
13
11
|
<table><tr>
|
14
12
|
<td><a target='_screenshot' href='assets/screen-main.png'><img src='assets/screen-main.png'/></a></td>
|
@@ -17,10 +15,7 @@ Screenshots (click to zoom)
|
|
17
15
|
<td><a target='_screenshot' href='assets/screen-search.png'><img src='assets/screen-search.png'/></a></td>
|
18
16
|
</tr></table>
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
Table of Contents
|
23
|
-
--------------------------------------------------
|
18
|
+
## Table of Contents
|
24
19
|
|
25
20
|
* [Install](#install)
|
26
21
|
* [Design Intentions](#design-intentions)
|
@@ -34,29 +29,31 @@ Table of Contents
|
|
34
29
|
* [Table of Contents Generation](#table-of-contents-generation)
|
35
30
|
* [Hidden Directories](#hidden-directories)
|
36
31
|
* [Controlling Sort Order](#controlling-sort-order)
|
32
|
+
* [Basic Authntication](#basic-authentication)
|
37
33
|
* [Customizing Theme](#customizing-theme)
|
38
34
|
* [Forcing HTTPS Connection](#forcing-https-connection)
|
39
35
|
* [Docker Image](#docker-image)
|
40
36
|
|
37
|
+
## Install
|
41
38
|
|
39
|
+
**Using Ruby:**
|
42
40
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
$ gem install madness
|
41
|
+
```shell
|
42
|
+
$ gem install madness
|
43
|
+
```
|
47
44
|
|
45
|
+
**Using Docker:**
|
48
46
|
|
47
|
+
```shell
|
48
|
+
$ alias madness='docker run --rm -it -v $PWD:/docs -p 3000:3000 dannyben/madness'
|
49
|
+
```
|
49
50
|
|
50
|
-
Design Intentions
|
51
|
-
--------------------------------------------------
|
51
|
+
## Design Intentions
|
52
52
|
|
53
53
|
Madness was designed in order to provide easy browsing, viewing and
|
54
54
|
searching for local, markdown based documentation directories.
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
Feature Highlights
|
59
|
-
--------------------------------------------------
|
56
|
+
## Feature Highlights
|
60
57
|
|
61
58
|
- Easy to use.
|
62
59
|
- Built-in full text search.
|
@@ -64,30 +61,25 @@ Feature Highlights
|
|
64
61
|
- Configure with a configuration file or command arguments.
|
65
62
|
- Fully customizable theme.
|
66
63
|
- Automatic generation of navigation sidebar.
|
67
|
-
- Automatic generation of Table of Contents.
|
64
|
+
- Automatic generation of Table of Contents (site-wide and inline).
|
68
65
|
|
69
|
-
|
70
|
-
|
71
|
-
Usage
|
72
|
-
--------------------------------------------------
|
66
|
+
## Usage
|
73
67
|
|
74
68
|
Go to any directory that contains markdown files and run:
|
75
69
|
|
76
|
-
|
70
|
+
```shell
|
71
|
+
$ madness
|
72
|
+
```
|
77
73
|
|
78
74
|
And open <http://localhost:3000> in your browser.
|
79
75
|
|
80
76
|
For more options, run:
|
81
77
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
[run madness with docker](#docker-image).
|
86
|
-
|
87
|
-
|
78
|
+
```shell
|
79
|
+
$ madness --help
|
80
|
+
```
|
88
81
|
|
89
|
-
Directory Conventions
|
90
|
-
--------------------------------------------------
|
82
|
+
## Directory Conventions
|
91
83
|
|
92
84
|
Madness expects to be executed in a documentation directory.
|
93
85
|
|
@@ -115,10 +107,7 @@ Example structure:
|
|
115
107
|
└── File.md
|
116
108
|
```
|
117
109
|
|
118
|
-
|
119
|
-
|
120
|
-
Configuration File
|
121
|
-
--------------------------------------------------
|
110
|
+
## Configuration File
|
122
111
|
|
123
112
|
All the command line arguments can also be configured through a
|
124
113
|
configuration file. Create a file named `.madness.yml` in your
|
@@ -136,7 +125,8 @@ highlighter: true
|
|
136
125
|
line_numbers: true
|
137
126
|
copy_code: true
|
138
127
|
index: false
|
139
|
-
|
128
|
+
search_limit: 100
|
129
|
+
dtoc: Table of Contents
|
140
130
|
theme: _theme
|
141
131
|
open: false
|
142
132
|
```
|
@@ -147,10 +137,7 @@ For convenience, you can get a template config file by running:
|
|
147
137
|
$ madness create config
|
148
138
|
```
|
149
139
|
|
150
|
-
|
151
|
-
|
152
|
-
Search
|
153
|
-
--------------------------------------------------
|
140
|
+
## Search
|
154
141
|
|
155
142
|
Madness comes with a full text search page. To activate it, you need to
|
156
143
|
generate a search index by running `madness --index` or
|
@@ -162,10 +149,7 @@ to your documentation server.
|
|
162
149
|
You will need to run this command from time to time, as your
|
163
150
|
documents change or new documents are added.
|
164
151
|
|
165
|
-
|
166
|
-
|
167
|
-
Images and Static Files
|
168
|
-
--------------------------------------------------
|
152
|
+
## Images and Static Files
|
169
153
|
|
170
154
|
You can put images and other asset files anywhere in your documentation
|
171
155
|
folder.
|
@@ -184,40 +168,37 @@ this markdown:
|
|
184
168
|
If you wish to link to images or pages in a different folder, simply specify
|
185
169
|
the path relative to the homepage:
|
186
170
|
|
187
|
-
```
|
171
|
+
```markdown
|
188
172
|
![alt text](/images/nice-picture.png)
|
189
173
|
```
|
190
174
|
|
191
|
-
|
192
|
-
|
193
|
-
Automatic H1
|
194
|
-
--------------------------------------------------
|
175
|
+
## Automatic H1
|
195
176
|
|
196
177
|
If your markdown document does not start with a level 1 heading, it
|
197
178
|
will be automatically added based on the file name.
|
198
179
|
|
180
|
+
## Table of Contents Generation
|
199
181
|
|
182
|
+
### Site-wide
|
200
183
|
|
201
|
-
Table of Contents
|
202
|
-
|
203
|
-
|
204
|
-
You can use the `madness --toc` command to generate a "Table of Contents"
|
205
|
-
markdown file.
|
184
|
+
To generate a Table of Contents file for the entire site (for the directories
|
185
|
+
and files), run `madness --toc FILENAME`
|
206
186
|
|
187
|
+
### Inline
|
207
188
|
|
189
|
+
If you have long markdown documents, and you wish to add an inline Table of
|
190
|
+
Contents for them, simply add an HTML comment `<!-- TOC -->` where you want
|
191
|
+
the Table of Contents to be generated. The inserted list will only consider
|
192
|
+
H2 and H3 headings.
|
208
193
|
|
209
|
-
Hidden Directories
|
210
|
-
--------------------------------------------------
|
194
|
+
## Hidden Directories
|
211
195
|
|
212
196
|
Directories that are made only of lowercase letters, underscoes, dash and/or
|
213
197
|
numbers (`/^[a-z_\-0-9]+$/`) will not be displayed in the navigation. In
|
214
198
|
other words, directories must have at least one uppercase letter or a space
|
215
199
|
to be recognized as a documentation directory.
|
216
200
|
|
217
|
-
|
218
|
-
|
219
|
-
Controlling Sort Order
|
220
|
-
--------------------------------------------------
|
201
|
+
## Controlling Sort Order
|
221
202
|
|
222
203
|
To control the sort order of the automatically generated navigation elements,
|
223
204
|
simply perfix your files and directories with digits followed by a dot and a
|
@@ -230,10 +211,17 @@ will be omitted when they are displayed.
|
|
230
211
|
└── 2. Another file or folder
|
231
212
|
```
|
232
213
|
|
214
|
+
## Basic Authentication
|
215
|
+
|
216
|
+
To add basic authentication, use the `--auth user:password` command line argument or the equivalent `auth` configuration option.
|
233
217
|
|
218
|
+
If you wish to avoid storing the basic authentication credentials in the configuration file, you may use ERB tags to load the credentials from environment variables:
|
219
|
+
|
220
|
+
```yaml
|
221
|
+
auth: <%= ENV['BASIC_AUTH'] %>
|
222
|
+
```
|
234
223
|
|
235
|
-
Customizing Theme
|
236
|
-
--------------------------------------------------
|
224
|
+
## Customizing Theme
|
237
225
|
|
238
226
|
There are two ways to change how Madness looks.
|
239
227
|
|
@@ -272,20 +260,16 @@ If you are looking to implement a smaller CSS change, follow these steps:
|
|
272
260
|
Note that this functionality is not guaranteed to stay as is in future
|
273
261
|
versions of madness.
|
274
262
|
|
275
|
-
|
276
|
-
|
277
|
-
Forcing HTTPS Connection
|
278
|
-
--------------------------------------------------
|
263
|
+
## Forcing HTTPS Connection
|
279
264
|
|
280
265
|
To have Madness redirect HTTP traffic to HTTPS, set this environment
|
281
266
|
variable:
|
282
267
|
|
283
|
-
|
284
|
-
|
285
|
-
|
268
|
+
```shell
|
269
|
+
$ export MADNESS_FORCE_SSL=1
|
270
|
+
```
|
286
271
|
|
287
|
-
Docker Image
|
288
|
-
--------------------------------------------------
|
272
|
+
## Docker Image
|
289
273
|
|
290
274
|
Madness server is also available as a docker image.
|
291
275
|
|
@@ -296,6 +280,13 @@ directory as the markdown documentation folder
|
|
296
280
|
$ docker run --rm -it -v $PWD:/docs -p 3000:3000 dannyben/madness
|
297
281
|
```
|
298
282
|
|
283
|
+
You may create an alias for convenience:
|
284
|
+
|
285
|
+
```shell
|
286
|
+
$ alias madness='docker run --rm -it -v $PWD:/docs -p 3000:3000 dannyben/madness'
|
287
|
+
$ medness --help
|
288
|
+
```
|
289
|
+
|
299
290
|
For more information about the docker image, see:
|
300
291
|
|
301
292
|
- [Madness image on Docker Hub][dockerhub]
|
data/app/public/css/main.css
CHANGED
@@ -245,8 +245,9 @@ nav {
|
|
245
245
|
nav .icon-bar {
|
246
246
|
border-bottom: 1px dotted #ddd; }
|
247
247
|
nav a.document, nav span.document, nav .caption {
|
248
|
+
border-bottom: 1px dotted #ddd;
|
248
249
|
display: block;
|
249
|
-
padding:
|
250
|
+
padding: 5px 20px 5px 30px; }
|
250
251
|
nav a.icon {
|
251
252
|
display: inline-block;
|
252
253
|
font-size: 1.5em;
|
data/app/public/css/main.css.map
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
|
-
"mappings": "AAAA,IAAK;EACH,oBAAoB,EAAE,IAAI;EAC1B,wBAAwB,EAAE,IAAI;EAC9B,KAAK,EAAE,IAAI;EAEX,WAAW,EAAE,mEAAmE;EAChF,SAAS,EAAE,IAAI;EACf,WAAW,EAAE,GAAG;EAChB,SAAS,EAAE,UAAU;;AAGvB,eAAgB;EACd,WAAW,EAAE,MAA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I;;AC5Bb,IAAK;EACH,SAAS,EAAE,MAAM;EACjB,MAAM,EAAE,MAAM;;AAGhB,KAAM;EACJ,OAAO,EAAE,iBAAiB;EAE1B,yBAAkB;IAChB,OAAO,EAAE,KAAK;IACd,OAAO,EAAE,EAAE;EJFd,yCAAgD;IIU7C,kBAAe;MACb,UAAU,EAAE,KAAK;MACjB,WAAW,EAAE,KAAK;EAItB,qBAAkB;IAChB,SAAS,EAAE,KAAK;IAChB,MAAM,EAAE,MAAM",
|
4
4
|
"sources": ["../../styles/_typography.scss","../../styles/_table.scss","../../styles/_anchor.scss","../../styles/_list.scss","../../styles/_code.scss","../../styles/_coderay.scss","../../styles/_image.scss","../../styles/_line.scss","../../styles/_keyboard.scss","../../styles/_search.scss","../../styles/_breadcrumbs.scss","../../styles/_nav.scss","../../styles/_mixins.scss","../../styles/_icons.scss","../../styles/_autocomplete.scss","../../styles/_general.scss","../../styles/main.scss"],
|
5
5
|
"names": [],
|
6
6
|
"file": "main.css"
|
data/app/styles/_nav.scss
CHANGED
@@ -20,13 +20,13 @@ nav {
|
|
20
20
|
}
|
21
21
|
|
22
22
|
a.document, span.document, .caption {
|
23
|
-
|
23
|
+
border-bottom: 1px dotted #ddd;
|
24
24
|
// &:hover {
|
25
25
|
// background: #e4e4e4;
|
26
26
|
// }
|
27
27
|
|
28
28
|
display: block;
|
29
|
-
padding:
|
29
|
+
padding: 5px 20px 5px 30px;
|
30
30
|
}
|
31
31
|
|
32
32
|
a.icon {
|
data/lib/madness.rb
CHANGED
data/lib/madness/breadcrumbs.rb
CHANGED
data/lib/madness/command_line.rb
CHANGED
@@ -22,7 +22,7 @@ module Madness
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
private
|
26
26
|
|
27
27
|
# Separate between the two main modes: Create something, or launch
|
28
28
|
# the server.
|
@@ -61,10 +61,14 @@ module Madness
|
|
61
61
|
# Get the arguments as provided by docopt, and set them to our own
|
62
62
|
# config object.
|
63
63
|
def set_config(args)
|
64
|
-
config.path
|
65
|
-
config.port
|
66
|
-
config.bind
|
67
|
-
config.toc
|
64
|
+
config.path = args['PATH'] if args['PATH']
|
65
|
+
config.port = args['--port'].to_i if args['--port']
|
66
|
+
config.bind = args['--bind'] if args['--bind']
|
67
|
+
config.toc = args['--toc'] if args['--toc']
|
68
|
+
config.search_limit = args['--search-limit'].to_i if args['--search-limit']
|
69
|
+
config.auth = args['--auth'] if args['--auth']
|
70
|
+
config.auth_realm = args['--auth-realm'] if args['--auth-realm']
|
71
|
+
|
68
72
|
config.auto_h1 = false if args['--no-auto-h1']
|
69
73
|
config.auto_nav = false if args['--no-auto-nav']
|
70
74
|
config.sidebar = false if args['--no-sidebar']
|
@@ -73,6 +77,7 @@ module Madness
|
|
73
77
|
config.copy_code = false if args['--no-copy-code']
|
74
78
|
config.index = true if args['--index']
|
75
79
|
config.open = true if args['--open']
|
80
|
+
|
76
81
|
config.theme = File.expand_path(args['--theme'], config.path) if args['--theme']
|
77
82
|
end
|
78
83
|
|
data/lib/madness/directory.rb
CHANGED
data/lib/madness/docopt.txt
CHANGED
@@ -16,17 +16,17 @@ Subcommands:
|
|
16
16
|
|
17
17
|
Parameters:
|
18
18
|
PATH:
|
19
|
-
|
20
|
-
(Config option: path)
|
19
|
+
Path to the markdown directory.
|
20
|
+
(Config option: path, default: .)
|
21
21
|
|
22
22
|
Options:
|
23
23
|
-p, --port NUMBER
|
24
24
|
Set server port number.
|
25
|
-
(Config option: port)
|
25
|
+
(Config option: port, default: 3000)
|
26
26
|
|
27
27
|
-b, --bind ADDRESS
|
28
28
|
Set server listen address.
|
29
|
-
(Config option: bind)
|
29
|
+
(Config option: bind, default: 0.0.0.0)
|
30
30
|
|
31
31
|
--no-auto-h1
|
32
32
|
By default, if a markdown document does not start with an H1 caption,
|
@@ -68,6 +68,18 @@ Options:
|
|
68
68
|
Generate a table of contents file.
|
69
69
|
(Config option: toc)
|
70
70
|
|
71
|
+
--search-limit LIMIT
|
72
|
+
Maximum number of results to show on the search page [default: 100].
|
73
|
+
(Config option: search_limit)
|
74
|
+
|
75
|
+
--auth USER:PASS
|
76
|
+
Enable basic authentication.
|
77
|
+
(Config option: auth)
|
78
|
+
|
79
|
+
--auth-realm REALM
|
80
|
+
The basic authentication realm.
|
81
|
+
(Config option: auth_realm, default: Madness)
|
82
|
+
|
71
83
|
--open
|
72
84
|
Open the browser pointing at the madness webserver.
|
73
85
|
(Config option: open)
|
@@ -83,6 +95,7 @@ Examples:
|
|
83
95
|
madness --no-sidebar --no-auto-nav
|
84
96
|
madness --index --and-quit
|
85
97
|
madness --toc "Table of Contents.md" --index --and-quit
|
98
|
+
madness --auth user:secret --port 4000
|
86
99
|
madness --theme _mytheme
|
87
100
|
madness create config
|
88
101
|
madness create theme
|
data/lib/madness/document.rb
CHANGED
@@ -47,19 +47,20 @@ module Madness
|
|
47
47
|
|
48
48
|
# Return the HTML for that document, force re-read.
|
49
49
|
def content!
|
50
|
-
|
50
|
+
[:empty, :missing].include?(type) ? "<h1>#{title}</h1>" : markdown_to_html
|
51
51
|
end
|
52
52
|
|
53
|
-
|
53
|
+
private
|
54
54
|
|
55
55
|
# Identify file, dir and type.
|
56
|
-
# :readme
|
57
|
-
#
|
58
|
-
# :file
|
59
|
-
# :empty
|
56
|
+
# :readme - in case the path is a directory, and it contains index.md
|
57
|
+
# or README.md
|
58
|
+
# :file - in case the path is a *.md file
|
59
|
+
# :empty - in case it is a folder without README.md or index.md
|
60
|
+
# :missing - in any other case, we don't know (will trigger 404)
|
60
61
|
def set_base_attributes
|
61
62
|
@dir = docroot
|
62
|
-
@type = :
|
63
|
+
@type = :missing
|
63
64
|
@file = ''
|
64
65
|
@title = 'Index'
|
65
66
|
|
@@ -98,6 +99,7 @@ module Madness
|
|
98
99
|
def markdown_to_html
|
99
100
|
doc = CommonMarker.render_doc markdown, :DEFAULT, [:table]
|
100
101
|
|
102
|
+
replace_toc_marker doc
|
101
103
|
add_anchor_ids doc
|
102
104
|
html = doc.to_html :UNSAFE
|
103
105
|
html = syntax_highlight(html) if config.highlighter
|
@@ -120,6 +122,34 @@ module Madness
|
|
120
122
|
end
|
121
123
|
end
|
122
124
|
|
125
|
+
# Replace <!-- TOC --> with a Table of Contents for the page
|
126
|
+
def replace_toc_marker(doc)
|
127
|
+
toc_marker = doc.find do |node|
|
128
|
+
node.type == :html and node.string_content.include? "<!-- TOC -->"
|
129
|
+
end
|
130
|
+
|
131
|
+
return unless toc_marker
|
132
|
+
|
133
|
+
toc = []
|
134
|
+
doc.walk do |node|
|
135
|
+
next unless node.type == :header
|
136
|
+
level = node.header_level
|
137
|
+
next unless level.between? 2, 3
|
138
|
+
text = node.first_child.string_content
|
139
|
+
|
140
|
+
if level == 2
|
141
|
+
toc << "- [#{text}](##{text.to_slug})"
|
142
|
+
else
|
143
|
+
toc << " - [#{text}](##{text.to_slug})"
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
toc = toc.join "\n"
|
148
|
+
toc = CommonMarker.render_doc toc
|
149
|
+
toc_marker.insert_after toc.first_child
|
150
|
+
toc_marker.insert_after CommonMarker.render_doc("## Table of Contents").first_child
|
151
|
+
end
|
152
|
+
|
123
153
|
# If the document does not start with an H1 tag, add it.
|
124
154
|
def prepend_h1(html)
|
125
155
|
unless html[0..3] == "<h1>"
|
data/lib/madness/item.rb
CHANGED
@@ -14,7 +14,7 @@ module Madness
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def href
|
17
|
-
|
17
|
+
path_without_extension.sub(/^#{docroot}/, '').to_href
|
18
18
|
end
|
19
19
|
|
20
20
|
def dir?
|
@@ -25,7 +25,7 @@ module Madness
|
|
25
25
|
type == :file
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
private
|
29
29
|
|
30
30
|
def label!
|
31
31
|
File.basename(path_without_extension).to_label
|
data/lib/madness/navigation.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'addressable'
|
2
|
+
|
1
3
|
module Madness
|
2
4
|
module StringRefinements
|
3
5
|
refine String do
|
@@ -5,6 +7,10 @@ module Madness
|
|
5
7
|
gsub regex, ''
|
6
8
|
end
|
7
9
|
|
10
|
+
def to_href
|
11
|
+
Addressable::URI.escape self
|
12
|
+
end
|
13
|
+
|
8
14
|
def to_slug
|
9
15
|
downcase.strip.gsub(' ', '-').remove(/[^\w-]/)
|
10
16
|
end
|
data/lib/madness/search.rb
CHANGED
@@ -33,7 +33,7 @@ module Madness
|
|
33
33
|
index = Index.new path: index_dir
|
34
34
|
|
35
35
|
results = []
|
36
|
-
index.search_each(query, limit:
|
36
|
+
index.search_each(query, limit: config.search_limit) do |doc_id, score|
|
37
37
|
filename = index[doc_id][:file].sub("#{@path}/", '')[0...-3]
|
38
38
|
highlights = index.highlight "content:(#{query.tr(' ',' OR ')}) ", doc_id, field: :content,
|
39
39
|
pre_tag: "<strong>", post_tag: "</strong>",
|
@@ -60,7 +60,7 @@ module Madness
|
|
60
60
|
"#{@path}/_index"
|
61
61
|
end
|
62
62
|
|
63
|
-
|
63
|
+
private
|
64
64
|
|
65
65
|
# We are going to avoid indexing of README.md when there is also an
|
66
66
|
# index.md in the same directory, to keep behavior consistent with the
|
@@ -91,6 +91,10 @@ module Madness
|
|
91
91
|
.join(' / ')
|
92
92
|
end
|
93
93
|
|
94
|
+
def config
|
95
|
+
@config ||= Settings.instance
|
96
|
+
end
|
97
|
+
|
94
98
|
def file_url(filename)
|
95
99
|
filename.remove(/\/(index|README)$/)
|
96
100
|
end
|
data/lib/madness/server.rb
CHANGED
@@ -4,6 +4,8 @@ module Madness
|
|
4
4
|
|
5
5
|
# The Sinatra server
|
6
6
|
class Server < ServerBase
|
7
|
+
using StringRefinements
|
8
|
+
|
7
9
|
get '/_search' do
|
8
10
|
query = params[:q]
|
9
11
|
results = query ? Search.new.search(query) : false
|
@@ -33,7 +35,7 @@ module Madness
|
|
33
35
|
content = doc.content
|
34
36
|
|
35
37
|
if doc.type == :readme and !path.empty? and path[-1] != '/'
|
36
|
-
redirect "#{path}/"
|
38
|
+
redirect "#{path.to_href}/"
|
37
39
|
end
|
38
40
|
|
39
41
|
nav = Navigation.new dir
|
@@ -43,6 +45,8 @@ module Madness
|
|
43
45
|
redirect to(nav.links.first.href)
|
44
46
|
end
|
45
47
|
|
48
|
+
status 404 if doc.type == :missing
|
49
|
+
|
46
50
|
slim :document, locals: {
|
47
51
|
content: content,
|
48
52
|
type: doc.type,
|
data/lib/madness/server_base.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
require '
|
1
|
+
# require 'sinatra/reloader'
|
2
2
|
require 'rack/ssl'
|
3
3
|
require 'sass'
|
4
4
|
require 'sass/plugin/rack'
|
5
5
|
require 'sinatra/base'
|
6
|
-
require 'sinatra/reloader'
|
7
6
|
require 'slim'
|
8
7
|
|
9
8
|
module Madness
|
@@ -19,11 +18,16 @@ module Madness
|
|
19
18
|
use Rack::SSL if ENV['MADNESS_FORCE_SSL']
|
20
19
|
set :root, File.expand_path('../../', __dir__)
|
21
20
|
set :server, :puma
|
21
|
+
set :environment, ENV['MADNESS_ENV'] || :production
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
# TODO: Uncomment when the upstream issue is resolved
|
24
|
+
# At this time, we cannot use reloader, since it prints deprecation
|
25
|
+
# warnings in Ruby 2.7
|
26
|
+
# ref: https://github.com/sinatra/sinatra/issues/1590
|
27
|
+
# configure :development do
|
28
|
+
# register Sinatra::Reloader
|
29
|
+
# also_reload "#{__dir__}/*.rb"
|
30
|
+
# end
|
27
31
|
|
28
32
|
# Since we cannot use any config values in the main body of the class,
|
29
33
|
# since they will be updated later, we need to set anything that relys
|
@@ -31,10 +35,11 @@ module Madness
|
|
31
35
|
# The CommandLine class and the test suite should both call
|
32
36
|
# `Server.prepare` before calling Server.run!
|
33
37
|
def self.prepare
|
34
|
-
use Madness::Static, root: "#{config.path}/", :
|
38
|
+
use Madness::Static, root: "#{config.path}/", urls: %w[/], cascade: true
|
35
39
|
set :bind, config.bind
|
36
40
|
set :port, config.port
|
37
41
|
|
42
|
+
set_basic_auth if config.auth
|
38
43
|
set_tempalate_locations
|
39
44
|
end
|
40
45
|
|
@@ -47,6 +52,12 @@ module Madness
|
|
47
52
|
Sass::Plugin.options[:css_location] = theme.css_target_path
|
48
53
|
end
|
49
54
|
|
55
|
+
def self.set_basic_auth
|
56
|
+
use Rack::Auth::Basic, config.auth_realm do |username, password|
|
57
|
+
config.auth.split(':') == [username, password]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
50
61
|
def self.config
|
51
62
|
Settings.instance
|
52
63
|
end
|
data/lib/madness/settings.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'singleton'
|
2
|
+
require 'extended_yaml'
|
2
3
|
|
3
4
|
module Madness
|
4
5
|
|
@@ -39,7 +40,7 @@ module Madness
|
|
39
40
|
'.madness.yml'
|
40
41
|
end
|
41
42
|
|
42
|
-
|
43
|
+
private
|
43
44
|
|
44
45
|
def defaults
|
45
46
|
{
|
@@ -49,12 +50,15 @@ module Madness
|
|
49
50
|
auto_h1: true,
|
50
51
|
highlighter: true,
|
51
52
|
line_numbers: true,
|
53
|
+
search_limit: 100,
|
52
54
|
copy_code: true,
|
53
55
|
index: false,
|
54
56
|
theme: nil,
|
55
57
|
open: false,
|
56
58
|
auto_nav: true,
|
57
|
-
sidebar: true
|
59
|
+
sidebar: true,
|
60
|
+
auth: false,
|
61
|
+
auth_realm: 'Madness'
|
58
62
|
}
|
59
63
|
end
|
60
64
|
|
@@ -63,7 +67,7 @@ module Madness
|
|
63
67
|
end
|
64
68
|
|
65
69
|
def file_data
|
66
|
-
file_exist? ?
|
70
|
+
file_exist? ? ExtendedYAML.load(filename).symbolize_keys : {}
|
67
71
|
end
|
68
72
|
|
69
73
|
end
|
data/lib/madness/static.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Madness
|
2
2
|
|
3
3
|
# The Madness::Static middleware delegates requests to
|
4
|
-
# Rack::
|
4
|
+
# Rack::Static middleware unless the request URI ends with .md
|
5
5
|
class Static
|
6
6
|
def initialize(app, options)
|
7
7
|
@app = app
|
8
|
-
@static =
|
8
|
+
@static = Rack::Static.new app, options
|
9
9
|
end
|
10
10
|
|
11
11
|
def call(env)
|
@@ -5,7 +5,7 @@ module Madness
|
|
5
5
|
|
6
6
|
attr_reader :dir
|
7
7
|
|
8
|
-
def initialize(dir=nil)
|
8
|
+
def initialize(dir = nil)
|
9
9
|
@dir = dir || docroot
|
10
10
|
end
|
11
11
|
|
@@ -18,9 +18,9 @@ module Madness
|
|
18
18
|
@toc ||= toc!.join("\n")
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
private
|
22
22
|
|
23
|
-
def toc!(path=dir, indent=0)
|
23
|
+
def toc!(path = dir, indent = 0)
|
24
24
|
list = Directory.new(path).list
|
25
25
|
|
26
26
|
result = []
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# Madness configuration file
|
2
2
|
# Uncomment any of the options below
|
3
3
|
|
4
|
-
# path:
|
5
|
-
# port:
|
6
|
-
# bind:
|
4
|
+
# path: .
|
5
|
+
# port: 3000
|
6
|
+
# bind: 0.0.0.0
|
7
7
|
# sidebar: true
|
8
8
|
# auto_h1: true
|
9
9
|
# auto_nav: true
|
@@ -12,5 +12,8 @@
|
|
12
12
|
# copy_code: true
|
13
13
|
# index: false
|
14
14
|
# toc: Table of Contents
|
15
|
+
# search_limit: 100
|
15
16
|
# theme: _theme
|
16
17
|
# open: false
|
18
|
+
# auth: false
|
19
|
+
# auth_zone: 'Madness'
|
data/lib/madness/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: madness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coderay
|
@@ -136,20 +136,6 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '4.0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: rack-contrib
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - "~>"
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '2.1'
|
146
|
-
type: :runtime
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - "~>"
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '2.1'
|
153
139
|
- !ruby/object:Gem::Dependency
|
154
140
|
name: rack-ssl
|
155
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -213,39 +199,47 @@ dependencies:
|
|
213
199
|
- !ruby/object:Gem::Version
|
214
200
|
version: 2.0.5
|
215
201
|
- !ruby/object:Gem::Dependency
|
216
|
-
name:
|
202
|
+
name: slim
|
217
203
|
requirement: !ruby/object:Gem::Requirement
|
218
204
|
requirements:
|
219
205
|
- - "~>"
|
220
206
|
- !ruby/object:Gem::Version
|
221
|
-
version: '
|
222
|
-
- - ">="
|
223
|
-
- !ruby/object:Gem::Version
|
224
|
-
version: 2.0.5
|
207
|
+
version: '4.0'
|
225
208
|
type: :runtime
|
226
209
|
prerelease: false
|
227
210
|
version_requirements: !ruby/object:Gem::Requirement
|
228
211
|
requirements:
|
229
212
|
- - "~>"
|
230
213
|
- !ruby/object:Gem::Version
|
231
|
-
version: '
|
232
|
-
|
214
|
+
version: '4.0'
|
215
|
+
- !ruby/object:Gem::Dependency
|
216
|
+
name: extended_yaml
|
217
|
+
requirement: !ruby/object:Gem::Requirement
|
218
|
+
requirements:
|
219
|
+
- - "~>"
|
233
220
|
- !ruby/object:Gem::Version
|
234
|
-
version:
|
221
|
+
version: '0.2'
|
222
|
+
type: :runtime
|
223
|
+
prerelease: false
|
224
|
+
version_requirements: !ruby/object:Gem::Requirement
|
225
|
+
requirements:
|
226
|
+
- - "~>"
|
227
|
+
- !ruby/object:Gem::Version
|
228
|
+
version: '0.2'
|
235
229
|
- !ruby/object:Gem::Dependency
|
236
|
-
name:
|
230
|
+
name: addressable
|
237
231
|
requirement: !ruby/object:Gem::Requirement
|
238
232
|
requirements:
|
239
233
|
- - "~>"
|
240
234
|
- !ruby/object:Gem::Version
|
241
|
-
version: '
|
235
|
+
version: '2.7'
|
242
236
|
type: :runtime
|
243
237
|
prerelease: false
|
244
238
|
version_requirements: !ruby/object:Gem::Requirement
|
245
239
|
requirements:
|
246
240
|
- - "~>"
|
247
241
|
- !ruby/object:Gem::Version
|
248
|
-
version: '
|
242
|
+
version: '2.7'
|
249
243
|
description: Start a markdown server in any directory
|
250
244
|
email: db@dannyben.com
|
251
245
|
executables:
|
@@ -333,7 +327,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
333
327
|
- !ruby/object:Gem::Version
|
334
328
|
version: '0'
|
335
329
|
requirements: []
|
336
|
-
rubygems_version: 3.
|
330
|
+
rubygems_version: 3.1.4
|
337
331
|
signing_key:
|
338
332
|
specification_version: 4
|
339
333
|
summary: Instant Markdown Server
|