Generate links when diary & wiki dir are the same
When generating links, we first check that the file is not a diary file as we don't want to include those in the list. That work is delegated to the `is_diary_file` function. Prior to this change, the function always returned true if the file was in the diary directory. This approach gives false positives for a wiki which has a flat structure and the wiki files and diary files share a directory. eg: let wiki.diary_rel_path = './' This change reuses existing diary functions from the diary.vim module to get an exact list of diary files to check against.
This commit is contained in:
		
				
					committed by
					
						
						Tinmarino
					
				
			
			
				
	
			
			
			
						parent
						
							1020ac51bf
						
					
				
				
					commit
					b96e82d6cc
				
			@@ -391,9 +391,11 @@ function! vimwiki#base#generate_links(create) abort
 | 
			
		||||
    call sort(links)
 | 
			
		||||
 | 
			
		||||
    let bullet = repeat(' ', vimwiki#lst#get_list_margin()) . vimwiki#lst#default_symbol().' '
 | 
			
		||||
    let l:diary_file_paths = vimwiki#diary#get_diary_files()
 | 
			
		||||
 | 
			
		||||
    for link in links
 | 
			
		||||
      let link_infos = vimwiki#base#resolve_link(link)
 | 
			
		||||
      if !vimwiki#base#is_diary_file(link_infos.filename)
 | 
			
		||||
      if !vimwiki#base#is_diary_file(link_infos.filename, copy(l:diary_file_paths))
 | 
			
		||||
        if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown'
 | 
			
		||||
          let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink1Template')
 | 
			
		||||
        else
 | 
			
		||||
@@ -2133,12 +2135,15 @@ function! s:clean_url(url) abort
 | 
			
		||||
  return join(url_l, ' ')
 | 
			
		||||
endfunction
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function! vimwiki#base#is_diary_file(filename) abort
 | 
			
		||||
  let file_path = vimwiki#path#path_norm(a:filename)
 | 
			
		||||
  let rel_path = vimwiki#vars#get_wikilocal('diary_rel_path')
 | 
			
		||||
  let diary_path = vimwiki#path#path_norm(vimwiki#vars#get_wikilocal('path') . rel_path)
 | 
			
		||||
  return rel_path !=? '' && file_path =~# '^'.vimwiki#u#escape(diary_path)
 | 
			
		||||
" An optional second argument allows you to pass in a list of diary files rather
 | 
			
		||||
" than generating a list on each call to the function.
 | 
			
		||||
function! vimwiki#base#is_diary_file(filename, ...) abort
 | 
			
		||||
  let l:diary_file_paths = a:0 > 0 ? a:1 : vimwiki#diary#get_diary_files()
 | 
			
		||||
  let l:normalised_file_paths =
 | 
			
		||||
        \ map(l:diary_file_paths, {_, path -> vimwiki#path#normalize(path)})
 | 
			
		||||
  let l:matching_files =
 | 
			
		||||
        \ filter(l:normalised_file_paths, {index, file -> file =~# a:filename})
 | 
			
		||||
  return len(l:matching_files) > 0 " filename is a diary file if match is found
 | 
			
		||||
endfunction
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -44,7 +44,7 @@ function! s:get_position_links(link) abort
 | 
			
		||||
  let idx = -1
 | 
			
		||||
  let links = []
 | 
			
		||||
  if a:link =~# '^\d\{4}-\d\d-\d\d'
 | 
			
		||||
    let links = map(s:get_diary_files(), 'fnamemodify(v:val, ":t:r")')
 | 
			
		||||
    let links = map(vimwiki#diary#get_diary_files(), 'fnamemodify(v:val, ":t:r")')
 | 
			
		||||
    " include 'today' into links
 | 
			
		||||
    if index(links, vimwiki#diary#diary_date_link()) == -1
 | 
			
		||||
      call add(links, vimwiki#diary#diary_date_link())
 | 
			
		||||
@@ -157,7 +157,7 @@ function! s:read_captions(files) abort
 | 
			
		||||
endfunction
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function! s:get_diary_files() abort
 | 
			
		||||
function! vimwiki#diary#get_diary_files() abort
 | 
			
		||||
  let rx = '^\d\{4}-\d\d-\d\d'
 | 
			
		||||
  let s_files = glob(vimwiki#vars#get_wikilocal('path').
 | 
			
		||||
        \ vimwiki#vars#get_wikilocal('diary_rel_path').'*'.vimwiki#vars#get_wikilocal('ext'))
 | 
			
		||||
@@ -201,7 +201,6 @@ function! s:sort(lst) abort
 | 
			
		||||
  endif
 | 
			
		||||
endfunction
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
" The given wiki number a:wnum is 1 for the first wiki, 2 for the second and so on. This is in
 | 
			
		||||
" contrast to most other places, where counting starts with 0. When a:wnum is 0, the current wiki
 | 
			
		||||
" is used.
 | 
			
		||||
 
 | 
			
		||||
@@ -20,12 +20,11 @@ else
 | 
			
		||||
  endfunction
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
" collapse sections like /a/b/../c to /a/c
 | 
			
		||||
" collapse sections like /a/b/../c to /a/c and /a/b/./c to /a/b/c
 | 
			
		||||
function! vimwiki#path#normalize(path) abort
 | 
			
		||||
  let path = a:path
 | 
			
		||||
  while 1
 | 
			
		||||
    let result = substitute(path, '/[^/]\+/\.\.', '', '')
 | 
			
		||||
    let result = substitute(path, '/[^/]\+/\.\.\|\./', '', '')
 | 
			
		||||
    if result ==# path
 | 
			
		||||
      break
 | 
			
		||||
    endif
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user