yass 0.4.0 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d520abe308c57950c7215ff67f420b807a04877c2c871e561fede4eff273d93a
4
- data.tar.gz: 10d65ec2011a5f8ba550d3781fec148cb0db646ccf33ae465abd81bbbeb1d0a8
3
+ metadata.gz: 73f51cc4416ff0b4de87b02a74f586f0896ad4ee1bf7f1825d19076229fc528a
4
+ data.tar.gz: 3da6e3a3b8ea3e0a6e45edaef4813f8ec83ada084daac8bfe6f83cf624b083d8
5
5
  SHA512:
6
- metadata.gz: e888b46f195cfcde35f56480555b07eaa150b8ad2d64f37fc81ceb67589cbe856d2b8acac7169b6bf8d42e5abc45b16246b7890986c9ad50aaba12406e841a71
7
- data.tar.gz: a25ceff7ecc103ef8106da4c19fb4dfbba78d523384c6bbe2f5a20b5f5189a791dd7ec69dbc900d765e5ea0a5c432b169b22677304fc973df550057f1d70d8ca
6
+ metadata.gz: a1760594401b2db23db4bc0b1fe8333b9d7b77ede41291ee5ace23c3a407d432b5360941570bb13eb1ea3f61f37f7c3d36e2d6da856561b0278e418380b37e00
7
+ data.tar.gz: 2911add8f4767f6aedd2ceb6c2708d966d05961161671d0eedc735f28ae6147379b6da142c7d6fce3162c9ee94cca4cd29d20bbe0f3275104dfdba85bd16710a
data/README.md CHANGED
@@ -22,7 +22,7 @@ $ yass init blog
22
22
  Creating blog/layouts/default.html.liquid
23
23
  Creating blog/site/assets/highlight-default.css
24
24
  Creating blog/site/assets/highlight.min.js
25
- Creating blog/site/index.default.html.liquid
25
+ Creating blog/site/index.html.liquid
26
26
  Creating blog/templates/css_links.liquid
27
27
  Creating blog/templates/js_scripts.liquid
28
28
  $ cd blog
@@ -36,16 +36,16 @@ The built site will be placed into `dist`.
36
36
  yass build
37
37
  ```
38
38
 
39
- If you're building for local viewing, use the `--local` option. It ensures any generated URLs ending in `/` have `.index.html` appended.
39
+ NOTE If you're building for webserverless, local viewing, and using the `skip_index` filter anywhere, use the `--no-skip-index` option.
40
40
 
41
41
  ```bash
42
- yass build --local
42
+ yass build --no-skip-index
43
43
  ```
44
44
 
45
45
  Use the `watch` command to continually build your site as files change.
46
46
 
47
47
  ```bash
48
- yass watch
48
+ yass watch # also supports --no-skip-index
49
49
  ```
50
50
 
51
51
  ## Layouts
@@ -96,12 +96,11 @@ NOTE: Liquid is pretty strict about template filenames. They must match `^[a-zA-
96
96
  An object representing the current page. Properties:
97
97
 
98
98
  * `title` A titleized version of the filename (e.g. *My File* from *my-file.html*)
99
- * `url` URL path to the file (note that *index.html* stripped unless the `--local` option is used)
100
- * `path` Same as `url` except *index.html* is never stripped
99
+ * `src_path` Path with the original filename (e.g. *foo/bar/zorp.md.liquid*)
100
+ * `path` URL path relative to the relative root (e.g. *foo/bar/zorp.html*)
101
101
  * `dirname` Directory file is in (e.g. *foo/bar* from *foo/bar/zorp.html*)
102
102
  * `filename` Name of file (e.g. *zorp.html* from *foo/bar/zorp.html*)
103
103
  * `extname` File extension (e.g. *.html* from *foo/bar/zorp.html*)
104
- * `src_path` Path with the original filename (e.g. *foo/index.md.liquid*)
105
104
 
106
105
  ### files
107
106
 
@@ -109,14 +108,20 @@ Any array of all files that will be written `dist/`. Same properties as `page`.
109
108
 
110
109
  ## Liquid filters
111
110
 
112
- ### relative_to
111
+ ### relative
113
112
 
114
- Modifies a path to be relative to another path. Useful in layouts and template that need to refer to another file.
113
+ Modifies a path to be relative to the current file. Useful in layouts and template that need to refer to other files.
115
114
 
116
115
  ```html
117
- <script src="{{ "assets/main.js" | relative_to: page.path }}"</script>
116
+ <script src="{{ "assets/main.js" | relative }}"</script>
118
117
  ```
119
118
 
119
+ If the above HTML was in `a/b/c.html.liquid`, the script source would be `../../assets/main.js`.
120
+
121
+ ### strip_index
122
+
123
+ Removes trailing `index.html`s from URLs, on the assumption that web servers will handle that. Can be disabled with the `--no-strip-index` option (useful for development builds).
124
+
120
125
  ### match
121
126
 
122
127
  Returns true if the string matches the regex.
@@ -51,7 +51,7 @@ yass <command> [options] [path/to/dir]
51
51
  Options:
52
52
  ).strip
53
53
  opts.on("--clean", "Remove unknown files from dist/ when bulding") { config.clean = true }
54
- opts.on("--local", "Build in local mode (with links to /index.html's)") { config.local = true }
54
+ opts.on("--no-strip-index", "Disable the strip_index Liquid filter") { config.strip_index = false }
55
55
  opts.on("--debug", "Print stack traces") { config.debug = true }
56
56
  opts.on("-h", "--help", "Prints this help") { config.stdout.puts opts; exit }
57
57
  }
@@ -65,7 +65,7 @@ yass <command> [options] [path/to/dir]
65
65
  templates: "templates",
66
66
  dest: "dist",
67
67
  clean: false,
68
- local: false,
68
+ strip_index: true,
69
69
  stdin: $stdin,
70
70
  stdout: $stdout,
71
71
  stderr: $stderr,
@@ -38,8 +38,11 @@ module Yass
38
38
  config.stdout.puts "Watching for changes..."
39
39
  watcher = Filewatcher.new([config.src_dir, config.layout_dir, config.template_dir].map(&:to_s))
40
40
  yield watcher if block_given?
41
+
42
+ Yass::CLI::Runner.build(config, argv: argv)
41
43
  watcher.watch do |changes|
42
44
  files = changes.map { |f, _| Pathname.new(f).relative_path_from(config.root).to_s }.reject { |f| Dir.exist? f }
45
+ # TODO use \r?
43
46
  config.stdout.puts "Building #{files.join ", "}"
44
47
  config.clear_cache!
45
48
  Yass::CLI::Runner.build(config, argv: argv)
data/lib/yass/config.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Yass
2
- Config = Struct.new(:root, :src, :dest, :layouts, :templates, :clean, :local, :stdin, :stdout, :stderr, :debug, keyword_init: true) do
2
+ Config = Struct.new(:root, :src, :dest, :layouts, :templates, :clean, :strip_index, :stdin, :stdout, :stderr, :debug, keyword_init: true) do
3
3
  def src_dir = root.join src
4
4
  def dest_dir = root.join dest
5
5
  def template_dir = root.join templates
@@ -11,7 +11,7 @@ module Yass
11
11
  def generate!
12
12
  dest_dirs.each { |dir| FileUtils.mkdir_p dir }
13
13
  config.sources.each do |source|
14
- outfile = config.dest_dir.join(source.relative_path)
14
+ outfile = config.dest_dir.join(source.src_path)
15
15
  if source.dynamic?
16
16
  outfile, content = generate(source, outfile)
17
17
  outfile.write content
@@ -30,7 +30,7 @@ module Yass
30
30
  content = Kramdown::Document.new(content).to_html
31
31
  return generate(source, outfile.sub(/\.md$/, ".html"), content)
32
32
  when ".liquid"
33
- template = LiquidTemplate.compile(config, source.relative_path, content)
33
+ template = LiquidTemplate.compile(config, source.src_path, content)
34
34
  content = template.render(source)
35
35
  return generate(source, outfile.sub(/\.liquid$/, ""), content)
36
36
  else
@@ -47,8 +47,6 @@ module Yass
47
47
  (actual_files - expected_files).each { |f| FileUtils.rm f }
48
48
  end
49
49
 
50
- def dest_dirs
51
- config.sources.map { |s| config.dest_dir.join(s.relative_path).dirname }.uniq
52
- end
50
+ def dest_dirs = config.sources.map { |s| s.outfile.dirname.to_s }.uniq
53
51
  end
54
52
  end
@@ -1,12 +1,23 @@
1
1
  module Yass
2
2
  module LiquidFilters
3
- def relative_to(url, to)
4
- url, to = Pathname.new(url), Pathname.new(to)
3
+ def relative(url)
4
+ url = Pathname.new(url)
5
+ to = context.registers[:source].dest_path
5
6
  in_root = to.dirname.to_s == "."
6
7
  updirs = in_root ? [] : to.dirname.to_s.split("/").map { ".." }
7
8
  Pathname.new([*updirs, url].join("/")).to_s
8
9
  end
9
10
 
11
+ def strip_index(url)
12
+ path = Pathname.new(url)
13
+ strip = path.basename.to_s == "index.html" && strip_index?
14
+ strip ? path.dirname.to_s : path.to_s
15
+ end
16
+
10
17
  def match(str, regex) = Regexp.new(regex).match? str
18
+
19
+ private
20
+
21
+ def strip_index? = context.registers[:source].config.strip_index
11
22
  end
12
23
  end
@@ -1,3 +1,5 @@
1
+ require 'cgi'
2
+
1
3
  module Yass
2
4
  module LiquidTags
3
5
  # Works like `render`, but passes the block content to the template as a variable named `content`
@@ -13,7 +15,10 @@ module Yass
13
15
 
14
16
  # Wraps the block content in HTML for Highlight.js
15
17
  class Highlight < Liquid::Block
16
- def render(_context) = %(<pre><code class="language-#{@markup.strip}">#{super}</code></pre>)
18
+ def render(context)
19
+ block = CGI.escapeHTML super.strip
20
+ %(<pre><code class="language-#{@markup.strip}">#{block}</code></pre>)
21
+ end
17
22
  end
18
23
  end
19
24
  end
@@ -15,7 +15,7 @@ module Yass
15
15
  def render(source)
16
16
  vars = { "page" => file_attrs(source), "files" => files_attrs(source.config.sources) }
17
17
  vars["content"] = yield if block_given?
18
- content = @template.render(vars, { strict_variables: true, strict_filters: true })
18
+ content = @template.render(vars, { strict_variables: true, strict_filters: true, registers: { source: source } })
19
19
  if @template.errors.any?
20
20
  source.config.stderr.puts "Errors found in #{name}:"
21
21
  source.config.stderr.puts @template.errors.map { |e| " #{e}" }.join("\n")
@@ -28,12 +28,12 @@ module Yass
28
28
  def file_attrs(source)
29
29
  {
30
30
  "title" => source.title,
31
- "url" => source.url.to_s,
32
31
  "path" => source.dest_path.to_s,
33
- "src_path" => source.relative_path.to_s,
34
- "dirname" => source.relative_path.dirname.to_s,
32
+ "src_path" => source.src_path.to_s,
33
+ "dirname" => source.dest_path.dirname.to_s,
35
34
  "filename" => source.dest_path.basename.to_s,
36
35
  "extname" => source.dest_path.basename.extname,
36
+ "filesize" => File.stat(source.path).size,
37
37
  }
38
38
  end
39
39
 
data/lib/yass/source.rb CHANGED
@@ -1,29 +1,26 @@
1
1
  module Yass
2
2
  class Source
3
3
  EXT_CONVERSIONS = {"md" => "html"}.freeze
4
- attr_reader :config, :path, :layout, :relative_path, :dest_path
4
+ attr_reader :config, :path, :layout, :src_path, :dest_path, :outfile
5
5
 
6
6
  def initialize(config, path)
7
7
  @config = config
8
8
  @path = path
9
- @relative_path = path.relative_path_from config.src_dir
10
- dest_filename, @layout= parse_name
11
- @dest_path = relative_path.dirname.join(dest_filename)
9
+ @src_path = path.relative_path_from config.src_dir
10
+ dest_filename, @layout = parse_name
11
+ @dest_path = src_path.dirname.join(dest_filename)
12
+ @outfile = config.dest_dir.join(dest_path)
12
13
  end
13
14
 
14
- def url = index? && !config.local ? dest_path.dirname : dest_path
15
-
16
15
  def title
17
16
  fname = dest_path.basename.sub(/\..+$/, "").to_s
18
- fname = relative_path.dirname.basename.to_s if fname == "index"
17
+ fname = src_path.dirname.basename.to_s if fname == "index"
19
18
  fname = "Home" if fname == "."
20
19
  fname.sub(/[_-]+/, " ").split(/ +/).map(&:capitalize).join(" ")
21
20
  end
22
21
 
23
22
  def dynamic? = !!(/\.(liquid|md)(\..+)?$/ =~ path.basename.to_s || layout)
24
23
 
25
- def index? = dest_path.basename.to_s == "index.html"
26
-
27
24
  private
28
25
 
29
26
  def parse_name
data/lib/yass/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yass
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.5.0".freeze
3
3
  end
@@ -4,8 +4,7 @@
4
4
  <meta charset="utf-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
6
  <title>{{ page.title }}</title>
7
- {% render "css_links", files: files, page: page %}
8
- {% render "js_scripts", files: files, page: page %}
7
+ {% render "asset_tags", files: files, page: page %}
9
8
  </head>
10
9
  <body>
11
10
  {{ content }}
@@ -0,0 +1,9 @@
1
+ /*!
2
+ Theme: Default
3
+ Description: Original highlight.js style
4
+ Author: (c) Ivan Sagalaev <maniac@softwaremaniacs.org>
5
+ Maintainer: @highlightjs/core-team
6
+ Website: https://highlightjs.org/
7
+ License: see project LICENSE
8
+ Touched: 2021
9
+ */pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{background:#f3f3f3;color:#444}.hljs-comment{color:#697070}.hljs-punctuation,.hljs-tag{color:#444a}.hljs-tag .hljs-attr,.hljs-tag .hljs-name{color:#444}.hljs-attribute,.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-name,.hljs-selector-tag{font-weight:700}.hljs-deletion,.hljs-number,.hljs-quote,.hljs-selector-class,.hljs-selector-id,.hljs-string,.hljs-template-tag,.hljs-type{color:#800}.hljs-section,.hljs-title{color:#800;font-weight:700}.hljs-link,.hljs-operator,.hljs-regexp,.hljs-selector-attr,.hljs-selector-pseudo,.hljs-symbol,.hljs-template-variable,.hljs-variable{color:#ab5656}.hljs-literal{color:#695}.hljs-addition,.hljs-built_in,.hljs-bullet,.hljs-code{color:#397300}.hljs-meta{color:#1f7199}.hljs-meta .hljs-string{color:#38a}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}
@@ -0,0 +1,9 @@
1
+ {% assign css_files = files | where: "extname", ".css" -%}
2
+ {% for file in css_files %}
3
+ <link rel="stylesheet" href="{{ file.path | relative }}">
4
+ {% endfor %}
5
+
6
+ {% assign js_files = files | where: "extname", ".js" -%}
7
+ {% for file in js_files %}
8
+ <script src="{{ file.path | relative }}"></script>
9
+ {% endfor %}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Hollinger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-05-09 00:00:00.000000000 Z
11
+ date: 2025-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: filewatcher
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
- description: A dead-simple static site generator
55
+ description: Yet Another Static Site (generator)
56
56
  email: jordan.hollinger@gmail.com
57
57
  executables:
58
58
  - yass
@@ -73,11 +73,10 @@ files:
73
73
  - lib/yass/source.rb
74
74
  - lib/yass/version.rb
75
75
  - site-template/layouts/default.html.liquid
76
- - site-template/site/assets/highlight-default.css
76
+ - site-template/site/assets/highlight.min.css
77
77
  - site-template/site/assets/highlight.min.js
78
78
  - site-template/site/index.html.liquid
79
- - site-template/templates/css_links.liquid
80
- - site-template/templates/js_scripts.liquid
79
+ - site-template/templates/asset_tags.liquid
81
80
  homepage: https://github.com/jhollinger/yass/
82
81
  licenses:
83
82
  - MIT
@@ -102,5 +101,5 @@ requirements: []
102
101
  rubygems_version: 3.4.19
103
102
  signing_key:
104
103
  specification_version: 4
105
- summary: Yet Another Static Site (generator)
104
+ summary: An astonishingly un-opinionated static site generator
106
105
  test_files: []
@@ -1,117 +0,0 @@
1
- pre code.hljs {
2
- display: block;
3
- overflow-x: auto;
4
- padding: 1em
5
- }
6
- code.hljs {
7
- padding: 3px 5px
8
- }
9
- /*!
10
- Theme: Default
11
- Description: Original highlight.js style
12
- Author: (c) Ivan Sagalaev <maniac@softwaremaniacs.org>
13
- Maintainer: @highlightjs/core-team
14
- Website: https://highlightjs.org/
15
- License: see project LICENSE
16
- Touched: 2021
17
- */
18
- /*
19
- This is left on purpose making default.css the single file that can be lifted
20
- as-is from the repository directly without the need for a build step
21
-
22
- Typically this "required" baseline CSS is added by `makestuff.js` during build.
23
- */
24
- pre code.hljs {
25
- display: block;
26
- overflow-x: auto;
27
- padding: 1em
28
- }
29
- code.hljs {
30
- padding: 3px 5px
31
- }
32
- /* end baseline CSS */
33
- .hljs {
34
- background: #F3F3F3;
35
- color: #444
36
- }
37
- /* Base color: saturation 0; */
38
- .hljs-subst {
39
- /* default */
40
-
41
- }
42
- /* purposely ignored */
43
- .hljs-formula,
44
- .hljs-attr,
45
- .hljs-property,
46
- .hljs-params {
47
-
48
- }
49
- .hljs-comment {
50
- color: #697070
51
- }
52
- .hljs-tag,
53
- .hljs-punctuation {
54
- color: #444a
55
- }
56
- .hljs-tag .hljs-name,
57
- .hljs-tag .hljs-attr {
58
- color: #444
59
- }
60
- .hljs-keyword,
61
- .hljs-attribute,
62
- .hljs-selector-tag,
63
- .hljs-meta .hljs-keyword,
64
- .hljs-doctag,
65
- .hljs-name {
66
- font-weight: bold
67
- }
68
- /* User color: hue: 0 */
69
- .hljs-type,
70
- .hljs-string,
71
- .hljs-number,
72
- .hljs-selector-id,
73
- .hljs-selector-class,
74
- .hljs-quote,
75
- .hljs-template-tag,
76
- .hljs-deletion {
77
- color: #880000
78
- }
79
- .hljs-title,
80
- .hljs-section {
81
- color: #880000;
82
- font-weight: bold
83
- }
84
- .hljs-regexp,
85
- .hljs-symbol,
86
- .hljs-variable,
87
- .hljs-template-variable,
88
- .hljs-link,
89
- .hljs-selector-attr,
90
- .hljs-operator,
91
- .hljs-selector-pseudo {
92
- color: #ab5656
93
- }
94
- /* Language color: hue: 90; */
95
- .hljs-literal {
96
- color: #695
97
- }
98
- .hljs-built_in,
99
- .hljs-bullet,
100
- .hljs-code,
101
- .hljs-addition {
102
- color: #397300
103
- }
104
- /* Meta color: hue: 200 */
105
- .hljs-meta {
106
- color: #1f7199
107
- }
108
- .hljs-meta .hljs-string {
109
- color: #38a
110
- }
111
- /* Misc effects */
112
- .hljs-emphasis {
113
- font-style: italic
114
- }
115
- .hljs-strong {
116
- font-weight: bold
117
- }
@@ -1,4 +0,0 @@
1
- {% assign css_files = files | where: "extname", ".css" -%}
2
- {% for file in css_files %}
3
- <link rel="stylesheet" href="{{ file.url | relative_to: page.url }}">
4
- {% endfor %}
@@ -1,4 +0,0 @@
1
- {% assign js_files = files | where: "extname", ".js" -%}
2
- {% for file in js_files %}
3
- <script src="{{ file.url | relative_to: page.url }}"></script>
4
- {% endfor %}