@@ -56,14 +56,17 @@ def mini_ez_links(urlo, base, end, url_whitespace, url_case):
56
56
base , url_blog = base
57
57
url_blog_path = [x for x in url_blog .split ('/' ) if len (x ) > 0 ]
58
58
url_blog_path = url_blog_path [len (url_blog_path ) - 1 ]
59
+ file_name = urlo [2 ].replace ('index' , '' )
60
+ file_name = file_name .replace ('../' , '' )
61
+ file_name = file_name .replace ('./' , '' )
62
+
59
63
all_docs = [
60
64
re .sub (rf"(.*)({ url_blog_path } )?/docs/*" , '' , x .replace ('\\ ' , '/' )).replace (
61
65
'.md' , ''
62
66
)
63
67
for x in iglob (str (base ) + os .sep + '**' , recursive = True )
64
68
if os .path .isfile (x )
65
69
]
66
- file_name = urlo [2 ].replace ('index' , '' )
67
70
file_found = [
68
71
'/' + x for x in all_docs if os .path .basename (x ) == file_name or x == file_name
69
72
]
@@ -167,6 +170,11 @@ def search_doc(md_link_path, all_docs):
167
170
return file [0 ]
168
171
return 0
169
172
173
+ def create_link (link ):
174
+ if link .endswith ('/' ):
175
+ return link [:- 1 ] + '.md'
176
+ else :
177
+ return link + '.md'
170
178
171
179
class EmbedFile (BasePlugin ):
172
180
config_scheme = (('param' , config_options .Type (str , default = '' )),)
@@ -192,35 +200,26 @@ def on_post_page(self, output_content, page, config):
192
200
):
193
201
if len (link ['src' ]) > 0 :
194
202
195
- if link ['src' ][0 ] == '.' :
196
- md_src_path = link ['src' ][3 :- 1 ] + '.md'
197
- md_src_path = md_src_path .replace ('.m.md' , '.md' )
198
- md_link_path = os .path .join (
199
- os .path .dirname (page .file .abs_src_path ), md_src_path
200
- )
201
- md_link_path = Path (unquote (md_link_path )).resolve ()
203
+ if link ['src' ][0 ] == '.' : #relative links
204
+ md_src = create_link (unquote (link ['src' ]))
205
+ md_link_path = Path (
206
+ os .path .dirname (page .file .abs_src_path ), md_src ).resolve ()
202
207
203
208
elif link ['src' ][0 ] == '/' :
204
- if link ['src' ].endswith ('/' ):
205
- md_src_path = link ['src' ][:- 1 ] + '.md'
206
- else :
207
- md_src_path = link ['src' ] + '.md'
209
+ md_src_path = create_link (unquote (link ['src' ]))
208
210
md_link_path = os .path .join (
209
211
config ['docs_dir' ], md_src_path )
210
212
md_link_path = Path (unquote (md_link_path )).resolve ()
211
213
212
214
elif link ['src' ][0 ] != '#' :
213
- if link ['src' ].endswith ('/' ):
214
- md_src_path = link ['src' ][:- 1 ] + '.md'
215
- else :
216
- md_src_path = link ['src' ] + '.md'
215
+ md_src_path = create_link (unquote (link ['src' ]))
217
216
218
217
md_link_path = os .path .join (
219
218
os .path .dirname (page .file .abs_src_path ), md_src_path
220
219
)
221
220
md_link_path = Path (unquote (md_link_path )).resolve ()
222
221
else :
223
- md_src_path = link ['src' ] + '.md'
222
+ md_src_path = create_link ( unquote ( link ['src' ]))
224
223
md_link_path = os .path .join (
225
224
os .path .dirname (page .file .abs_src_path ), md_src_path
226
225
)
0 commit comments