-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.rb
More file actions
125 lines (96 loc) · 3.23 KB
/
config.rb
File metadata and controls
125 lines (96 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
require "ohhighmark"
# Activate and configure extensions
# https://middlemanapp.com/advanced/configuration/#configuring-extensions
activate :autoprefixer do |prefix|
prefix.browsers = "last 2 versions"
end
# Layouts
# https://middlemanapp.com/basics/layouts/
# Per-page layout changes
page '/*.xml', layout: false
page '/*.json', layout: false
page '/*.txt', layout: false
# With alternative layout
# page '/path/to/file.html', layout: 'other_layout'
# Proxy pages
# https://middlemanapp.com/advanced/dynamic-pages/
# proxy(
# '/this-page-has-no-template.html',
# '/template-file.html',
# locals: {
# which_fake_page: 'Rendering a fake page with a local variable'
# },
# )
# Helpers
helpers do
include OhHighMark::Helper
def first_name
data.site[:name].split(" ").first
end
def nav_link(name, url, options = {})
active = current_page.url == url || (url != "/" && current_page.url.start_with?(url))
classes = [options[:class], ("active" if active)].compact.join(" ")
# Compute relative URL when relative_links is enabled
if config[:relative_links]
# Use destination_path instead of path because with directory_indexes enabled,
# source files like projects.html are built to projects/index.html
# We need the actual output path to calculate correct relative URLs
current_dir = File.dirname(current_page.destination_path)
depth = directory_depth(current_dir)
if url == "/"
# Root: go up one level for each directory component
url = depth == 0 ? "./" : "../" * depth
else
# Other pages: compute relative path from current directory
relative_path = url.sub(%r{^/}, '')
# Add trailing slash for directory indexes
relative_path += '/' unless relative_path.end_with?('/')
url = depth == 0 ? relative_path : "../" * depth + relative_path
end
end
link_to name, url, options.merge(class: classes)
end
private
def directory_depth(dir)
dir == '.' ? 0 : dir.split('/').reject(&:empty?).length
end
public
def data_to_markdown_table(d)
headers = d.map { |c| c[:title].to_s }
rows = d.map { |c| Array(c[:names]).map(&:to_s) }
row_count = rows.map(&:length).max || 0
# normalize
normalized = rows.map do |col|
col + Array.new(row_count - col.length, "")
end
# Compute column widths
widths = headers.each_with_index.map do |h, i|
([h] + normalized[i]).map(&:length).max
end
lines = []
# Header
lines << "| " + headers.each_with_index.map { |h, i|
h.ljust(widths[i])
}.join(" | ") + " |"
# Separator
lines << "| " + widths.map { |w| "-" * w }.join(" | ") + " |"
# Body
row_count.times do |r|
lines << "| " + normalized.each_with_index.map { |col, i|
col[r].ljust(widths[i])
}.join(" | ") + " |"
end
lines.join("\n")
end
end
activate :directory_indexes
# Build-specific configuration
# https://middlemanapp.com/advanced/configuration/#environment-specific-settings
configure :build do
# Enable relative assets for GitHub Pages
activate :relative_assets
set :relative_links, true
# Optionally minify assets
# activate :minify_css
# activate :minify_javascript, compressor: Terser.new
end