-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathshortcode.liquid
131 lines (107 loc) · 4.44 KB
/
shortcode.liquid
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
126
127
128
129
130
131
{%- capture loadnew -%}{{- load | replace: '<!--[', '[' -}}{%- endcapture -%}
{%- capture loadnew -%}{{- loadnew | replace: ']-->', ']' -}}{%- endcapture -%}
{%- capture loadnew -%}{{- loadnew | replace: ']</p>', ']' -}}{%- endcapture -%}
{%- capture loadnew -%}{{- loadnew | replace: '<p>[', '[' -}}{%- endcapture -%}
{%- assign shortcodeBeginnings = loadnew | split: '[' -%}
{%- if shortcodeBeginnings.size > 1 -%}
{%- for shortcodeBegin in shortcodeBeginnings -%}
{%- assign forloopNextIndex = forloop.index0 | plus: 1 -%}
{%- comment -%}
// First Iteration will contain everithing before the first shortcode
{%- endcomment -%}
{%- if forloop.first -%}
{{-shortcodeBegin-}}
{%- else -%}
{%- assign shortcodeEndings = shortcodeBegin | split: ']' -%}
{%- assign contentAfterClosingTag = shortcodeEndings[1] -%}
{%- capture shortcodeFull -%}{{-shortcodeEndings[0]-}}{%- endcapture -%}
{%- assign shortcodes = shortcodeFull | split: '"' -%}
{%- assign variables = '' -%}
{%- assign keys = '' -%}
{%- assign thecycle = 'even' -%}
{%- for section in shortcodes -%}
{%- if thecycle == 'odd' -%}
{%- assign thecycle = 'even' -%}
{%- else -%}
{%- assign thecycle = 'odd'-%}
{%- endif -%}
{%- if forloop.first -%}
{%- comment -%}
// Handle Closing Tags and pass 'content'
{%- endcomment -%}
{%- assign sectionSpace = section | split: ' ' -%}
{%- assign content = '' -%}
{%- assign currentSection = sectionSpace[0] -%}
{%- assign nextSection = shortcodeBeginnings[forloopNextIndex] -%}
{%- assign nextSection = nextSection | split: ']' -%}
{%- assign nextSection = nextSection[0] -%}
{%- assign nextSection = nextSection | replace: '/', '' -%}
{%- if currentSection == nextSection -%}
{%- assign content = content | append: contentAfterClosingTag -%}
{%- assign variables = variables | append: content | append: '||' -%}
{%- assign keys = keys | append: 'content' | append: '||' -%}
{%- assign contentAfterClosingTag = '' -%}
{%- endif -%}
{%- if forloop.last -%}
{%- for space in sectionSpace -%}
{%- comment -%}
// First Iteration will setup the correct template
{%- endcomment -%}
{%- if forloop.first -%}
{%- assign template = space | prepend: 'shortcode-' -%}
{%- else -%}
{%- if forloop.last -%}
{%- assign variables = variables | append: space | append: '||' -%}
{%- else -%}
{%- assign variables = variables | append: space | append: '||' -%}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- capture output -%}{%- assign buildVariables = variables | split: '||' -%}{%- include template variable: buildVariables -%}{%- endcapture -%}
{%- if output contains 'Liquid error' -%}
[{{- shortcodeFull -}}]
{%- else -%}
{{-output-}}
{%- endif -%}
{%- else -%}
{%- assign sectionSpace = section | split: ' ' -%}
{%- for space in sectionSpace -%}
{%- if forloop.first -%}
{%- assign template = sectionSpace.first | prepend: 'shortcode-' -%}
{%- else -%}
{%- if forloop.last -%}
{%- assign keys = keys | append: space | replace: '=', ''| append: '||' -%}
{%- else -%}
{%- assign keys = keys | append: "nokey_" | append: space | replace: '=', ''| append: '||' -%}
{%- assign variables = variables | append: space | append: '||' -%}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- else -%}
{%- if forloop.last -%}
{%- assign variables = variables | append: section -%}
{%- assign variablesFinal = variables | split: '||' -%}
{%- assign keysFinal = keys | replace: ' ', '' | split: '||' -%}
{%- capture output -%}{%- include template variable: variablesFinal key: keysFinal -%}{%- endcapture -%}
{%- if output contains 'Liquid error' -%}
[{{- shortcodeFull -}}]
{%- else -%}
{{-output-}}
{%- endif -%}
{%- else -%}
{%- if thecycle == 'even' -%}
{%- assign variables = variables | append: section | append: '||' -%}
{%- endif -%}
{%- if thecycle == 'odd' -%}
{%- assign keys = keys | append: section | replace: '=', ''| append: '||' -%}
{%- endif -%}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{{-contentAfterClosingTag-}}
{%- endif -%}
{%- endfor -%}
{%- else -%}
{{- load -}}
{%- endif -%}