wai-website-plugin 0.0.1
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/lib/wai-website-plugin.rb +74 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3cd471e081efefa1cefab4370a5a3b239679026e780ddb0460943d852c710573
|
4
|
+
data.tar.gz: b86e9090227a9ae70fc7bd8e0858df747d838240421081a57b3449c5c0c5758e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cc431e87b9d92b972c20b1578a0a43227eaa4cc7ec3dd56722871b4129cc3c010327531b5a80d31055a5323a3d05e778163a0ef02f4c62fc2631e1be12b5d01f
|
7
|
+
data.tar.gz: e292a7984b9dc496b4250b460aa75e302a73ba24855141d1b8e1237f102ff2f9bc8d10e967aae1907cd1222cf7e7f458edfdae9880c658c7a9d8d92d197c7941
|
@@ -0,0 +1,74 @@
|
|
1
|
+
def getPage (site, ref, lang = "en")
|
2
|
+
translatedpages = site.documents.find_all {|a| a.data['ref'] == ref}
|
3
|
+
translatedpages = translatedpages.concat(site.pages.find_all {|a| a.data['ref'] == ref})
|
4
|
+
return translatedpages.find {|a| a.data['lang'] == lang}
|
5
|
+
end
|
6
|
+
|
7
|
+
def transform(document, inenglishtext)
|
8
|
+
|
9
|
+
unless document.content == ""
|
10
|
+
|
11
|
+
if document.data['lang'] == 'en'
|
12
|
+
inenglishtext = ""
|
13
|
+
else
|
14
|
+
inenglishtext = ' (' + inenglishtext +')'
|
15
|
+
end
|
16
|
+
document.content.gsub!(/\[\[([^\]\]]+?)\]\]\((?!\/TR)(?!\/WAI)(\/.*?\/)(?:#(.*?))?\)/i) do |match|
|
17
|
+
translatedpage = getPage document.site, Regexp.last_match[2], document.data['lang']
|
18
|
+
if Regexp.last_match[3].nil?
|
19
|
+
fragment = ''
|
20
|
+
# Jekyll.logger.debug "Eric’s Hook X2:", Regexp.last_match[1] + "|" + Regexp.last_match[2] + Regexp.last_match[3]
|
21
|
+
else
|
22
|
+
fragment = '#' + Regexp.last_match[3]
|
23
|
+
end
|
24
|
+
if translatedpage.nil?
|
25
|
+
'<<' + Regexp.last_match[1] +'>>({{ "' + Regexp.last_match[2] +'" | relative_url }}'+ fragment+'){: hreflang="en"}' + inenglishtext
|
26
|
+
else
|
27
|
+
'<<' + translatedpage.data['title'] +'>>({{ "' + translatedpage.data['permalink'] + '" | relative_url }}'+ fragment+')'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
document.content.gsub!(/\[([^\]]+?)\]\((?!\/TR)(?!\/WAI)(\/.*?\/)(?:#(.*?))?\)/i) do |match|
|
32
|
+
translatedpage = getPage document.site, Regexp.last_match[2], document.data['lang']
|
33
|
+
if Regexp.last_match[3].nil?
|
34
|
+
fragment = ''
|
35
|
+
# Jekyll.logger.debug "Eric’s Hook X2:", Regexp.last_match[1] + "|" + Regexp.last_match[2] + Regexp.last_match[3]
|
36
|
+
else
|
37
|
+
fragment = '#' + Regexp.last_match[3]
|
38
|
+
end
|
39
|
+
if translatedpage.nil?
|
40
|
+
'[' + Regexp.last_match[1] +']({{ "' + Regexp.last_match[2] +'" | relative_url }}'+ fragment+'){: hreflang="en"}' + inenglishtext
|
41
|
+
else
|
42
|
+
'[' + Regexp.last_match[1] +']({{ "' + translatedpage.data['permalink'] + '" | relative_url }}'+ fragment+')'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
document.content.gsub!(/<<([^>>]+?)>>/i) do |match|
|
47
|
+
'[' + Regexp.last_match[1] +']'
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
Jekyll::Hooks.register :documents, :pre_render do |document|
|
55
|
+
inenglishtext = document.site.data['translations'].find {|a| a['en'] == 'in English'}
|
56
|
+
inenglishtext = inenglishtext[document.data['lang']]
|
57
|
+
if inenglishtext.nil?
|
58
|
+
inenglishtext = "in English"
|
59
|
+
end
|
60
|
+
# Jekyll.logger.debug "Eric’s Hook EN:", inenglishtext
|
61
|
+
|
62
|
+
transform document, inenglishtext
|
63
|
+
end
|
64
|
+
|
65
|
+
Jekyll::Hooks.register :pages, :pre_render do |document|
|
66
|
+
inenglishtext = document.site.data['translations'].find {|a| a['en'] == 'in English'}
|
67
|
+
inenglishtext = inenglishtext[document.data['lang']]
|
68
|
+
if inenglishtext.nil?
|
69
|
+
inenglishtext = "in English"
|
70
|
+
end
|
71
|
+
# Jekyll.logger.debug "Eric’s Hook EN:", inenglishtext
|
72
|
+
|
73
|
+
transform document, inenglishtext
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wai-website-plugin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Eggert
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: ''
|
14
|
+
email:
|
15
|
+
- ee@w3.org
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/wai-website-plugin.rb
|
21
|
+
homepage: https://www.w3.org/WAI/
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubygems_version: 3.0.3
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: ''
|
44
|
+
test_files: []
|