Skip to content

Commit

Permalink
i18n (#9): 'اختبارات' agora funciona; jekyll-datapage-generator.rb, r…
Browse files Browse the repository at this point in the history
…ascunho de sanitize_filename_i18n
  • Loading branch information
fititnt committed May 18, 2021
1 parent fd7dafd commit f7daeeb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
12 changes: 12 additions & 0 deletions _data/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
title: HDX - The Humanitarian Data Exchange API
noindex: true

# Note: this is just a test to check if non US-ASCII characters can work with
# Hapi toolchain
- x-default: /mul/api/UN/HDX/
uid: /arb/api/UN/اختبارات/
linguam: arb
typum: api
gid: UN
# lid: HDX
openapi_filum: /api/UN/HDX/eng/openapi.yaml
title: "اختبارات"
noindex: true

## -----------------------------------------------------------------------------
- x-default: /mul/api/UN/reliefweb/
uid: /mul/api/UN/reliefweb/
Expand Down
32 changes: 28 additions & 4 deletions _plugins/jekyll-datapage-generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@ def sanitize_filename(name)
"AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz"
).downcase.strip.gsub(' ', '-').gsub(/[^\w.-]/, '')
end

# sanitize_filename_i18n is a (work in progress) variant of
# sanitize_filename. The idea here is not acindentaly strip non-US-ASCII
#
# @see https://apidock.com/ruby/Regexp
#
def sanitize_filename_i18n(name)
if(name.is_a? Integer)
return name.to_s
end
return name.strip
# Whitespace character ([:blank:], newline, carriage return, etc.)
# replaced by -
.gsub(/[[:space:]]/, '-')
# /[[:cntrl:]]/ - Control character
# remove any one present
.gsub(/[[:cntrl:]]/, '')

# TODO: investigate usage of
# /[[:word:]]/ - A character in one of the following Unicode
# general categories Letter, Mark, Number, Connector_Punctuation
end
end

# this class is used to tell Jekyll to generate a page
Expand Down Expand Up @@ -88,9 +110,10 @@ def initialize(site, base, index_files, dir, dir_expr, page_data_prefix, data, n
end
puts "debug (datapage-gen). will use '#{raw_title}' as the page title" if debug
end

filename = sanitize_filename(raw_filename).to_s


# filename = sanitize_filename(raw_filename).to_s
filename = sanitize_filename_i18n(raw_filename).to_s

# Old option, without dir_expr
# @dir = dir + (index_files ? "/" + filename + "/" : "")

Expand Down Expand Up @@ -219,7 +242,8 @@ module DataPageLinkGenerator
# need to generate the links by hand
def datapage_url(input, dir)
extension = @context.registers[:site].config['page_gen-dirs'] ? '/' : '.html'
"#{dir}/#{sanitize_filename(input)}#{extension}"
# "#{dir}/#{sanitize_filename(input)}#{extension}"
"#{dir}/#{sanitize_filename_i18n(input)}#{extension}"
end
end

Expand Down
5 changes: 5 additions & 0 deletions _plugins/jekyll-hapi-hooks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# # https://jekyllrb.com/docs/plugins/hooks/
# Jekyll::Hooks.register :pages, :post_render do |page|
# # code to call after Jekyll renders a page
# puts "oi"
# end

0 comments on commit f7daeeb

Please sign in to comment.