markita 1.0.210828
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +159 -0
- data/bin/markita +43 -0
- data/data/favicon.ico +0 -0
- data/data/highlight.css +81 -0
- data/data/login_failed.html +7 -0
- data/data/login_form.html +10 -0
- data/data/not_found.html +7 -0
- data/lib/markita/base.rb +129 -0
- data/lib/markita/config.rb +18 -0
- data/lib/markita/plug/about.rb +31 -0
- data/lib/markita/plug/favicon.rb +13 -0
- data/lib/markita/plug/highlight.rb +13 -0
- data/lib/markita/plug/login.rb +37 -0
- data/lib/markita/plug/plugs.rb +1 -0
- data/lib/markita.rb +24 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a93274ab77ea3d606b0c0c696c73914786ee9baf0c7c880bdceec4cb1ae4cb6e
|
4
|
+
data.tar.gz: 7395b0d8d21fb98e929f5ca68548129fd6ccb713f8ef383504bbc59d0bd36436
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 90097792167ea98b81bad5a4682d680c323ed23c7507b355c53c05127b4f1a7177fe04f5df68522d432d4b84fa623c0e620b2f3dfdab44a72e7f07d5b6740180
|
7
|
+
data.tar.gz: 41d9d9716c26f65dc41f183e6d0bbf3ba93bdfe00690ce60fd2282958165ba5074cb641125d9dedfcabed4347ace94fca09c591d1d7382c0390fe5f433b5d333
|
data/README.md
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
# Markita
|
2
|
+
|
3
|
+
* [VERSION 1.0.210828](https://github.com/carlosjhr64/markita/releases)
|
4
|
+
* [github](https://www.github.com/carlosjhr64/markita)
|
5
|
+
* [rubygems](https://rubygems.org/gems/markita)
|
6
|
+
|
7
|
+
## DESCRIPTION
|
8
|
+
|
9
|
+
A [Sinatra](http://sinatrarb.com) Markdown server.
|
10
|
+
|
11
|
+
Uses [Kramdown](https://kramdown.gettalong.org/index.html) for the Markdown to
|
12
|
+
HTML conversion.
|
13
|
+
|
14
|
+
## INSTALL
|
15
|
+
```shell
|
16
|
+
$ gem install markita
|
17
|
+
```
|
18
|
+
## HELP
|
19
|
+
```shell
|
20
|
+
$ markita --help
|
21
|
+
Usage:
|
22
|
+
markita [:options+]
|
23
|
+
Options:
|
24
|
+
--root=DIRECTORY ~/vimwiki
|
25
|
+
--bind=BIND 0.0.0.0
|
26
|
+
--port=PORT 8080
|
27
|
+
--allowed=IPS
|
28
|
+
--no_about
|
29
|
+
--no_favicon
|
30
|
+
--no_highlight
|
31
|
+
--no_login
|
32
|
+
--no_plugs
|
33
|
+
Types:
|
34
|
+
DIRECTORY /^~?[\/\w\.]+$/
|
35
|
+
BIND /^[\w\.]+$/
|
36
|
+
PORT /^\d+$/
|
37
|
+
THEME /^[\w\.]+$/
|
38
|
+
IPS /^[\d\.\,]+$/
|
39
|
+
# NOTE:
|
40
|
+
# Assuming site is in ~/vimwiki,
|
41
|
+
# when ~/vimwiki/.valid-id is set with a sha256sum of a password,
|
42
|
+
# that password will restrict the site.
|
43
|
+
# Allowed IPs bypass the need for site password
|
44
|
+
# when the site is accessed from those locations.
|
45
|
+
```
|
46
|
+
## FEATURES
|
47
|
+
|
48
|
+
* Check(Ballot) boxes for task lists
|
49
|
+
* Image placement hints
|
50
|
+
* One line forms
|
51
|
+
* Template substitutions
|
52
|
+
* ONLY SERVES MARKDOWN PAGES:`/**/*.md`(omit extension `.md` in the url)
|
53
|
+
* ONLY SERVES PNG and GIF IMAGES: `/**/*.png`, and `/**/*.gif`
|
54
|
+
* See [`lib/markita/plug`](lib/markita/plug) for examples of plugins
|
55
|
+
|
56
|
+
Optionally:
|
57
|
+
|
58
|
+
* Place your custom `/favicon.ico`
|
59
|
+
* Place your custom `/highlight.css`
|
60
|
+
* Place `/.cert.crt` and `/.pkey.pem` for SSL(https)
|
61
|
+
* Place `sha256sum` of site's password in `/.valid-id`
|
62
|
+
|
63
|
+
## HOW-TOs
|
64
|
+
|
65
|
+
### Set site password:
|
66
|
+
```shell
|
67
|
+
$ # Assuming ~/vimwiki is your site's root...
|
68
|
+
$ echo -n '<SitePasswordHere>' | sha256sum | grep -o '^\w*' > ~/vimwiki/.valid-id
|
69
|
+
```
|
70
|
+
### Set site custom favicon, css, not found page, and login form and fail page:
|
71
|
+
```shell
|
72
|
+
$ # Assuming ~/vimwiki is your site's root...
|
73
|
+
$ # Note that you'll have to restart the server on any change to these:
|
74
|
+
$ cp /path-to/custom/favicon.ico ~/vimwiki/favicon.ico
|
75
|
+
$ cp /path-to/custom/highlight.css ~/vimwiki/highlight.css
|
76
|
+
$ cp /path-to/custom/not_found.html ~/vimwiki/not_found.html
|
77
|
+
$ cp /path-to/custom/login_form.html ~/vimwiki/login_form.html
|
78
|
+
$ cp /path-to/custom/login_fail.html ~/vimwiki/login_fail.html
|
79
|
+
```
|
80
|
+
### Run site in https:
|
81
|
+
```
|
82
|
+
$ # Assuming ~/vimwiki is your site's root...
|
83
|
+
$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout pkey.pem -out cert.crt
|
84
|
+
$ # Stuff happens... Answer all the dumb questions... then:
|
85
|
+
$ mv cert.crt ~/vimwiki/.cert.crt
|
86
|
+
$ mv pkey.pem ~/vimwiki/.pkey.pem
|
87
|
+
```
|
88
|
+
### Allow localhost to bypass password:
|
89
|
+
```shell
|
90
|
+
$ # Assuming ~/vimwiki with a site password set...
|
91
|
+
$ markita --allowed=127.0.0.1
|
92
|
+
./bin/markita-1.0.210826
|
93
|
+
== Sinatra (v2.1.0) has taken the stage on 8080 for development with backup from Thin
|
94
|
+
```
|
95
|
+
### Ballot boxes
|
96
|
+
```txt
|
97
|
+
- [ ] This is an emty ballot box
|
98
|
+
- [x] This is a checked ballot box
|
99
|
+
```
|
100
|
+
### Image placement hints:
|
101
|
+
```txt
|
102
|
+
Left and right spaces of the alternate text of an image hints placement.
|
103
|
+
The following image will be placed centered.
|
104
|
+
|
105
|
+

|
106
|
+
|
107
|
+

|
108
|
+
The above specified image will float left.
|
109
|
+
|
110
|
+

|
111
|
+
The above specified image will float right.
|
112
|
+
```
|
113
|
+
### One line forms
|
114
|
+
```txt
|
115
|
+
This will do a get method form:
|
116
|
+
|
117
|
+
Google:[q](https://www.google.com/search)
|
118
|
+
|
119
|
+
Due to the password field, this will do a post method form:
|
120
|
+
|
121
|
+
Username:[user] Password:[*pwd](/login.html)
|
122
|
+
```
|
123
|
+
### Template substitutions
|
124
|
+
```txt
|
125
|
+
In the template string, uppercase keys are CGI escaped:
|
126
|
+
|
127
|
+
<!-- template: "* [&query;](https://www.google.com/search?q=&QUERY;)" -->
|
128
|
+
<!-- regx: /^\* (?<query>.*)$/ -->
|
129
|
+
* Grumpy Cat
|
130
|
+
* It's over 9000!
|
131
|
+
|
132
|
+
The substitutions are active until the end of the block.
|
133
|
+
If template is not provided, the line itself will be the template.
|
134
|
+
```
|
135
|
+
## LICENSE
|
136
|
+
|
137
|
+
Copyright 2021 CarlosJHR64
|
138
|
+
|
139
|
+
Permission is hereby granted, free of charge,
|
140
|
+
to any person obtaining a copy of this software and
|
141
|
+
associated documentation files (the "Software"),
|
142
|
+
to deal in the Software without restriction,
|
143
|
+
including without limitation the rights
|
144
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
145
|
+
copies of the Software, and
|
146
|
+
to permit persons to whom the Software is furnished to do so,
|
147
|
+
subject to the following conditions:
|
148
|
+
|
149
|
+
The above copyright notice and this permission notice
|
150
|
+
shall be included in all copies or substantial portions of the Software.
|
151
|
+
|
152
|
+
THE SOFTWARE IS PROVIDED "AS IS",
|
153
|
+
WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
154
|
+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
155
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
156
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
157
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
158
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
|
159
|
+
THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/bin/markita
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'help_parser'
|
3
|
+
require 'markita'
|
4
|
+
|
5
|
+
OPTIONS = HelpParser[Markita::VERSION, <<HELP]
|
6
|
+
Usage:
|
7
|
+
markita [:options+]
|
8
|
+
Options:
|
9
|
+
--root=DIRECTORY \t ~/vimwiki
|
10
|
+
--bind=BIND \t 0.0.0.0
|
11
|
+
--port=PORT \t 8080
|
12
|
+
--allowed=IPS
|
13
|
+
--no_about
|
14
|
+
--no_favicon
|
15
|
+
--no_highlight
|
16
|
+
--no_login
|
17
|
+
--no_plugs
|
18
|
+
Types:
|
19
|
+
DIRECTORY /^~?[\\/\\w\\.]+$/
|
20
|
+
BIND /^[\\w\\.]+$/
|
21
|
+
PORT /^\\d+$/
|
22
|
+
THEME /^[\\w\\.]+$/
|
23
|
+
IPS /^[\\d\\.\\,]+$/
|
24
|
+
# NOTE:
|
25
|
+
# Assuming site is in ~/vimwiki,
|
26
|
+
# when ~/vimwiki/.valid-id is set with a sha256sum of a password,
|
27
|
+
# that password will restrict the site.
|
28
|
+
# Allowed IPs bypass the need for site password
|
29
|
+
# when the site is accessed from those locations.
|
30
|
+
HELP
|
31
|
+
begin
|
32
|
+
Markita.run!
|
33
|
+
rescue LoadError
|
34
|
+
HelpParser::REDTTY["#{$!.class}: #{$!.message}"]
|
35
|
+
exit 72
|
36
|
+
rescue RuntimeError
|
37
|
+
HelpParser::REDTTY["#{$!.class}: #{$!.message}"]
|
38
|
+
exit 65
|
39
|
+
rescue Exception
|
40
|
+
$stderr.puts $!.backtrace
|
41
|
+
HelpParser::REDTTY["#{$!.class}: #{$!.message}"]
|
42
|
+
exit 70
|
43
|
+
end
|
data/data/favicon.ico
ADDED
Binary file
|
data/data/highlight.css
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
/* Ruby Gem Rouge's base16.light */
|
2
|
+
.highlight table td { padding: 5px; }
|
3
|
+
.highlight table pre { margin: 0; }
|
4
|
+
.highlight, .highlight .w {
|
5
|
+
color: #303030;
|
6
|
+
}
|
7
|
+
.highlight .err {
|
8
|
+
color: #151515;
|
9
|
+
background-color: #ac4142;
|
10
|
+
}
|
11
|
+
.highlight .c, .highlight .ch, .highlight .cd, .highlight .cm, .highlight .cpf, .highlight .c1, .highlight .cs {
|
12
|
+
color: #505050;
|
13
|
+
}
|
14
|
+
.highlight .cp {
|
15
|
+
color: #f4bf75;
|
16
|
+
}
|
17
|
+
.highlight .nt {
|
18
|
+
color: #f4bf75;
|
19
|
+
}
|
20
|
+
.highlight .o, .highlight .ow {
|
21
|
+
color: #d0d0d0;
|
22
|
+
}
|
23
|
+
.highlight .p, .highlight .pi {
|
24
|
+
color: #d0d0d0;
|
25
|
+
}
|
26
|
+
.highlight .gi {
|
27
|
+
color: #90a959;
|
28
|
+
}
|
29
|
+
.highlight .gd {
|
30
|
+
color: #ac4142;
|
31
|
+
}
|
32
|
+
.highlight .gh {
|
33
|
+
color: #6a9fb5;
|
34
|
+
background-color: #151515;
|
35
|
+
font-weight: bold;
|
36
|
+
}
|
37
|
+
.highlight .k, .highlight .kn, .highlight .kp, .highlight .kr, .highlight .kv {
|
38
|
+
color: #aa759f;
|
39
|
+
}
|
40
|
+
.highlight .kc {
|
41
|
+
color: #d28445;
|
42
|
+
}
|
43
|
+
.highlight .kt {
|
44
|
+
color: #d28445;
|
45
|
+
}
|
46
|
+
.highlight .kd {
|
47
|
+
color: #d28445;
|
48
|
+
}
|
49
|
+
.highlight .s, .highlight .sb, .highlight .sc, .highlight .dl, .highlight .sd, .highlight .s2, .highlight .sh, .highlight .sx, .highlight .s1 {
|
50
|
+
color: #90a959;
|
51
|
+
}
|
52
|
+
.highlight .sa {
|
53
|
+
color: #aa759f;
|
54
|
+
}
|
55
|
+
.highlight .sr {
|
56
|
+
color: #75b5aa;
|
57
|
+
}
|
58
|
+
.highlight .si {
|
59
|
+
color: #8f5536;
|
60
|
+
}
|
61
|
+
.highlight .se {
|
62
|
+
color: #8f5536;
|
63
|
+
}
|
64
|
+
.highlight .nn {
|
65
|
+
color: #f4bf75;
|
66
|
+
}
|
67
|
+
.highlight .nc {
|
68
|
+
color: #f4bf75;
|
69
|
+
}
|
70
|
+
.highlight .no {
|
71
|
+
color: #f4bf75;
|
72
|
+
}
|
73
|
+
.highlight .na {
|
74
|
+
color: #6a9fb5;
|
75
|
+
}
|
76
|
+
.highlight .m, .highlight .mb, .highlight .mf, .highlight .mh, .highlight .mi, .highlight .il, .highlight .mo, .highlight .mx {
|
77
|
+
color: #90a959;
|
78
|
+
}
|
79
|
+
.highlight .ss {
|
80
|
+
color: #90a959;
|
81
|
+
}
|
data/data/not_found.html
ADDED
data/lib/markita/base.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
module Markita
|
2
|
+
class Base < Sinatra::Base
|
3
|
+
set bind: OPTIONS&.bind || '0.0.0.0'
|
4
|
+
set port: OPTIONS&.port || '8080'
|
5
|
+
set sessions: true
|
6
|
+
|
7
|
+
def Base.run!
|
8
|
+
puts "#{$0}-#{VERSION}"
|
9
|
+
super do |server|
|
10
|
+
if ['.cert.crt', '.pkey.pem'].all?{ File.exist? File.join(ROOT, _1)}
|
11
|
+
server.ssl = true
|
12
|
+
server.ssl_options = {
|
13
|
+
:cert_chain_file => File.join(ROOT, '.cert.crt'),
|
14
|
+
:private_key_file => File.join(ROOT, '.pkey.pem'),
|
15
|
+
:verify_peer => false,
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def Base.header(key)
|
22
|
+
<<-HEADER
|
23
|
+
<!DOCTYPE html>
|
24
|
+
<html>
|
25
|
+
<head>
|
26
|
+
<title>#{key}</title>
|
27
|
+
#{HEADER_LINKS}</head>
|
28
|
+
<body>
|
29
|
+
|
30
|
+
HEADER
|
31
|
+
end
|
32
|
+
|
33
|
+
def Base.footer
|
34
|
+
<<-FOOTER
|
35
|
+
|
36
|
+
</body>
|
37
|
+
</html>
|
38
|
+
FOOTER
|
39
|
+
end
|
40
|
+
|
41
|
+
def Base.pre_process(text)
|
42
|
+
val,string,_ = {},'',nil
|
43
|
+
text.each_line do |line|
|
44
|
+
line.chomp!
|
45
|
+
case line
|
46
|
+
when ''
|
47
|
+
val.clear
|
48
|
+
when val[:regx]
|
49
|
+
# Template/Substitutions
|
50
|
+
line=_ if _=val[:template]
|
51
|
+
$~.named_captures.each do |name, value|
|
52
|
+
line = line.gsub("&#{name};", value)
|
53
|
+
line = line.gsub("&#{name.upcase};", CGI.escape(value))
|
54
|
+
end
|
55
|
+
when %r(^<!-- (.*) -->$)
|
56
|
+
directive = $1
|
57
|
+
case directive
|
58
|
+
when %r(^(\w+): "(.*)"$)
|
59
|
+
val[$1.to_sym] = $2
|
60
|
+
when %r(^(\w+): /(.*)/)
|
61
|
+
val[$1.to_sym] = Regexp.new $2
|
62
|
+
else
|
63
|
+
$stderr.puts "Unrecognized directive: "+directive
|
64
|
+
end
|
65
|
+
next
|
66
|
+
end
|
67
|
+
string << line << "\n"
|
68
|
+
end
|
69
|
+
return string
|
70
|
+
end
|
71
|
+
|
72
|
+
def Base.post_process(text)
|
73
|
+
string,_ = '',nil
|
74
|
+
text.each_line do |line|
|
75
|
+
line.chomp!
|
76
|
+
case line
|
77
|
+
when %r(^(\s*)<li>\[(x| )\] (.*)</li>$)
|
78
|
+
# Task Lists
|
79
|
+
s,x,item = $1,$2,$3
|
80
|
+
li = (x=='x')?
|
81
|
+
%q{<li style="list-style-type: '☑ '">} :
|
82
|
+
%q{<li style="list-style-type: '☐ '">}
|
83
|
+
line = s+li+item+"</li>"
|
84
|
+
when %r(^<p>(\w+:\[\*?\w+\] )+\((\S+)\)</p>$)
|
85
|
+
# One Line Forms
|
86
|
+
action,method,form = $2,'get',''
|
87
|
+
line.scan(/(\w+):\[(\*)?(\w+)\] /).each do |field, pwd, name|
|
88
|
+
type = (pwd)? 'password' : 'text'
|
89
|
+
method = 'post' if pwd
|
90
|
+
form << %Q{ #{field}:<input type="#{type}" name="#{name}">\n}
|
91
|
+
end
|
92
|
+
line = %Q(<form action="#{action}" method="#{method}">\n) +
|
93
|
+
form + %Q( <input type="submit">\n</form>)
|
94
|
+
when %r(^<p><img (src="[^"]*" alt=" [^"]* ") /></p>$)
|
95
|
+
line = %Q(<img style="display: block; margin-left: auto; margin-right: auto;" #{$1} />)
|
96
|
+
when %r(^<p><img (src="[^"]*" alt=" [^"]*") />$)
|
97
|
+
line = %Q(<p><img style="float: left;" #{$1} />)
|
98
|
+
when %r(^<p><img (src="[^"]*" alt="[^"]* ") />$)
|
99
|
+
line = %Q(<p><img style="float: right;" #{$1} />)
|
100
|
+
end
|
101
|
+
string << line << "\n"
|
102
|
+
end
|
103
|
+
return string
|
104
|
+
end
|
105
|
+
|
106
|
+
def Base.page(key)
|
107
|
+
Base.header(key) + yield + Base.footer
|
108
|
+
end
|
109
|
+
|
110
|
+
get PAGE_KEY do |key|
|
111
|
+
filepath = File.join ROOT, key+'.md'
|
112
|
+
raise Sinatra::NotFound unless File.exist? filepath
|
113
|
+
text = File.read(filepath).force_encoding('utf-8')
|
114
|
+
Base.page(key){ Base.post_process markdown Base.pre_process text}
|
115
|
+
end
|
116
|
+
|
117
|
+
get IMAGE_PATH do |path, *_|
|
118
|
+
send_file File.join(ROOT, path)
|
119
|
+
end
|
120
|
+
|
121
|
+
get '/' do
|
122
|
+
redirect '/index'
|
123
|
+
end
|
124
|
+
|
125
|
+
not_found do
|
126
|
+
NOT_FOUND
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Markita
|
2
|
+
OPTIONS ||= nil
|
3
|
+
|
4
|
+
HEADER_LINKS = ''
|
5
|
+
|
6
|
+
ROOT = File.expand_path OPTIONS&.root || '~/vimwiki'
|
7
|
+
raise "Missing site root directory: "+ROOT unless File.directory? ROOT
|
8
|
+
APPDATA = File.join File.dirname(File.dirname __dir__), 'data'
|
9
|
+
PATH = lambda do |basename|
|
10
|
+
[ROOT, APPDATA].map{ File.join _1, basename}.detect{ File.exist? _1}
|
11
|
+
end
|
12
|
+
NOT_FOUND = File.read PATH['not_found.html']
|
13
|
+
|
14
|
+
PAGE_KEY = %r{/(\w[\w\/\-]*\w)}
|
15
|
+
IMAGE_PATH = %r{/(\w[\w\/\-]*\w\.((png)|(gif)))}
|
16
|
+
|
17
|
+
START_TIME = Time.now
|
18
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Markita
|
2
|
+
class Base
|
3
|
+
module About
|
4
|
+
def self.page
|
5
|
+
text = <<~TEXT
|
6
|
+
# [Markita](https://github.com/carlosjhr64/markita)
|
7
|
+
|
8
|
+
* VERSION: #{VERSION}
|
9
|
+
* ROOT: #{ROOT.sub(%r{^/home/\w+/},'~/')}
|
10
|
+
* ARGV: #{ARGV.join(' ')}
|
11
|
+
* START_TIME: #{START_TIME}
|
12
|
+
|
13
|
+
## Plug.html routes:
|
14
|
+
|
15
|
+
TEXT
|
16
|
+
Base.routes['GET'].each do |route|
|
17
|
+
path = route[0].to_s
|
18
|
+
next unless %r{^/\w+\.html$}.match? path
|
19
|
+
basename = File.basename(path, '.*')
|
20
|
+
text << "* [#{basename}](#{path})\n"
|
21
|
+
end
|
22
|
+
text << "\n\n" if defined? Favicon
|
23
|
+
text
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
get '/about.html' do
|
28
|
+
Base.page('about') { markdown About.page}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Markita
|
2
|
+
class Base < Sinatra::Base
|
3
|
+
HEADER_LINKS << %Q( <link rel="icon" type="image/x-icon" href="/favicon.ico">\n)
|
4
|
+
module Favicon
|
5
|
+
ICO = File.read PATH['favicon.ico']
|
6
|
+
end
|
7
|
+
|
8
|
+
get '/favicon.ico' do
|
9
|
+
headers 'Content-Type' => 'image/x-icon'
|
10
|
+
Favicon::ICO
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Markita
|
2
|
+
class Base < Sinatra::Base
|
3
|
+
HEADER_LINKS << %Q( <link rel="stylesheet" href="/highlight.css" type="text/css">\n)
|
4
|
+
module Highlight
|
5
|
+
CSS = File.read PATH['highlight.css']
|
6
|
+
end
|
7
|
+
|
8
|
+
get '/highlight.css' do
|
9
|
+
headers 'Content-Type' => 'text/css'
|
10
|
+
Highlight::CSS
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Markita
|
2
|
+
class Base
|
3
|
+
module Login
|
4
|
+
ID = File.exist?(_=File.join(ROOT, '.valid-id')) ?
|
5
|
+
File.read(_).strip :
|
6
|
+
nil
|
7
|
+
IPS = (_=OPTIONS&.allowed)? _.split(',') : nil
|
8
|
+
if IPS and not ID
|
9
|
+
raise "Allowed ips without site password does not make sense."
|
10
|
+
end
|
11
|
+
FORM = File.read PATH['login_form.html']
|
12
|
+
FAILED = File.read PATH['login_failed.html']
|
13
|
+
end
|
14
|
+
|
15
|
+
before do
|
16
|
+
unless Login::ID.nil? or Login::IPS&.include?(request.ip)
|
17
|
+
if id = params[:id]
|
18
|
+
session[:id] = Digest::SHA256.hexdigest id
|
19
|
+
end
|
20
|
+
if session[:id] == Login::ID
|
21
|
+
redirect '/' if request.path_info == '/login.html'
|
22
|
+
else
|
23
|
+
redirect '/login.html' unless request.path_info == '/login.html'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
puts "#{request.ip} #{request.path_info}"
|
27
|
+
end
|
28
|
+
|
29
|
+
get '/login.html' do
|
30
|
+
Login::FORM
|
31
|
+
end
|
32
|
+
|
33
|
+
post '/login.html' do
|
34
|
+
Login::FAILED
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir.glob(File.join Markita::ROOT, 'plug', '*.rb').each{ require _1}
|
data/lib/markita.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Markita
|
2
|
+
VERSION = '1.0.210828'
|
3
|
+
|
4
|
+
def self.run!
|
5
|
+
# Standard libraries
|
6
|
+
require 'digest'
|
7
|
+
require 'cgi'
|
8
|
+
# Gems
|
9
|
+
require 'sinatra/base'
|
10
|
+
require 'kramdown'
|
11
|
+
require 'thin'
|
12
|
+
Tilt.register Tilt::KramdownTemplate, 'md'
|
13
|
+
# Local
|
14
|
+
require_relative 'markita/config.rb'
|
15
|
+
require_relative 'markita/base.rb'
|
16
|
+
# Plugs
|
17
|
+
require_relative 'markita/plug/favicon.rb' unless OPTIONS&.no_favicon
|
18
|
+
require_relative 'markita/plug/highlight.rb' unless OPTIONS&.no_highlight
|
19
|
+
require_relative 'markita/plug/login.rb' unless OPTIONS&.no_login
|
20
|
+
require_relative 'markita/plug/about.rb' unless OPTIONS&.no_about
|
21
|
+
require_relative 'markita/plug/plugs.rb' unless OPTIONS&.no_plugs
|
22
|
+
Base.run!
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: markita
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.210828
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- CarlosJHR64
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-08-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: help_parser
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '7.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 7.0.200907
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '7.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 7.0.200907
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: sinatra
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.1'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 2.1.0
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '2.1'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.1.0
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: kramdown
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '2.3'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 2.3.1
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.3'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 2.3.1
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: thin
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - "~>"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '1.8'
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.8.1
|
83
|
+
type: :runtime
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.8'
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 1.8.1
|
93
|
+
description: |
|
94
|
+
A [Sinatra](http://sinatrarb.com) Markdown server.
|
95
|
+
|
96
|
+
Uses [Kramdown](https://kramdown.gettalong.org/index.html) for the Markdown to
|
97
|
+
HTML conversion.
|
98
|
+
email: carlosjhr64@gmail.com
|
99
|
+
executables:
|
100
|
+
- markita
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- README.md
|
105
|
+
- bin/markita
|
106
|
+
- data/favicon.ico
|
107
|
+
- data/highlight.css
|
108
|
+
- data/login_failed.html
|
109
|
+
- data/login_form.html
|
110
|
+
- data/not_found.html
|
111
|
+
- lib/markita.rb
|
112
|
+
- lib/markita/base.rb
|
113
|
+
- lib/markita/config.rb
|
114
|
+
- lib/markita/plug/about.rb
|
115
|
+
- lib/markita/plug/favicon.rb
|
116
|
+
- lib/markita/plug/highlight.rb
|
117
|
+
- lib/markita/plug/login.rb
|
118
|
+
- lib/markita/plug/plugs.rb
|
119
|
+
homepage: https://github.com/carlosjhr64/markita
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubygems_version: 3.2.22
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: A [Sinatra](http://sinatrarb.com) Markdown server.
|
142
|
+
test_files: []
|