Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to arrange diary file with a more organized folder structure? #1368

Open
4 tasks done
ericsunplus opened this issue Sep 13, 2023 · 7 comments
Open
4 tasks done

Comments

@ericsunplus
Copy link

Prior to submitting a new issue make sure to complete these steps:

  • Include the VimWiki settings from your .vimrc
let g:vimwiki_conceal_pre = 1
let g:vimwiki_valid_html_tags = 'b,i,s,u,sub,sup,kbd,br,hr,span'
let g:vimwiki_valid_html_tags = 'b,i,s,u,sub,sup,kbd,br,hr,span'
let g:vimwiki_menu = ''
let g:vimwiki_use_calendar = 1
  • Include the syntax you are using (default / Markdown / MediaWiki)
    default
  • Include the output of :VimwikiShowVersion.
Version: 2023.04.04
Os: Windows
Vim: 900
Branch: master

Revision: 71edcf6

Date: 2023-04-04 20:28:34 -0600
  • Provide a detailed description of the problem including steps to reproduce the issue.
    I am using vimwiki diary to record daily work notes. With days expands, the diary file are flat scattered in the same directory. As the following screenshot shows
    image
    It can be imagined after years the folder will have hundreds of files in single layer.

Is it possible we can provide an option to arrange these daily diary files in a more structured way, like what is done in index file?

diary_rel_path
    |
    +--- 2022
    |      |
    |      +--- Dec
    |            |
    |            +--- 2022-12-06.wiki
    |            |
    |            +--- ...
    |
    +--- 2023
           |
           +--- Jan
           |     |
           |     +--- 2023-01-01.wiki
           |     |
           |     +--- ...
           |
           +--- Feb
           |     |
           |     +--- 2023-02-01.wiki
           |     |
           |     +--- ...
           |
           +--- ...
@Jaeyong-Cho
Copy link

Jaeyong-Cho commented Sep 14, 2023

Hi,

I think my configuration could be of help to you.
The diary file path is hard-coded in vimwiki/autoload/diary.vim.

Therefore, I have modified diary.vim like this:

# line 100
- return strftime('%Y-%m-%f', l:computed_timestamp)
+ return strftime('%Y/%m/%f', l:computed_timestamp)

# line 505
- return link = a:year.'-'.month.'-'.day
+ return link = a:year.'/'.month.'/'.day

# line 532
- \ . a:year.'-'.month.'-'.day.vimwiki#vars#get_wikilocal('ext')
+ \ . a:year.'/'.month.'/'.day.vimwiki#vars#get_wikilocal('ext')

The result is like this:

diary_rel_path
    |
    +--- 2022
    |      |
    |      +--- 12
    |            |
    |            +--- 06.wiki
    |            |
    |            +--- ...
    |
    +--- 2023
           |
           +--- 1
           |     |
           |     +--- 01.wiki
           |     |
           |     +--- ...
           +--- 2
           |     |
           |     +--- 01.wiki
           |     |
           |     +--- ...
           |
           +--- ...

@ericsunplus
Copy link
Author

Hi @Jaeyong-Cho , thanks for your hints, I will try on my side and let you know

@ericsunplus
Copy link
Author

ericsunplus commented Sep 14, 2023

@Jaeyong-Cho , is diary index generating OK on your side after the change?
\wi : open the diary index
\w\i : refresh the diray index

My local patch is as the following. (I still want the node file name be 2023-04-14.wiki so make some minor change based on your patch

M autoload/vimwiki/diary.vim
@@ -97,7 +97,7 @@ function! vimwiki#diary#diary_date_link(...) abort
     let l:computed_timestamp = localtime() + l:delta_periods*l:day_s
   endif
 
-  return strftime('%Y-%m-%d', l:computed_timestamp)
+  return strftime('%Y/%m/%Y-%m-%d', l:computed_timestamp)
 
 endfunction
 
@@ -502,7 +502,7 @@ function! vimwiki#diary#calendar_action(day, month, year, week, dir) abort
   let day = s:prefix_zero(a:day)
   let month = s:prefix_zero(a:month)
 
-  let link = a:year.'-'.month.'-'.day
+  let link = a:year.'/'.month.'/'.year.'-'.month.'-'.day
   if winnr('#') == 0
     if a:dir ==? 'V'
       vsplit
@@ -529,7 +529,7 @@ function! vimwiki#diary#calendar_sign(day, month, year) abort
   let day = s:prefix_zero(a:day)
   let month = s:prefix_zero(a:month)
   let sfile = vimwiki#vars#get_wikilocal('path') . vimwiki#vars#get_wikilocal('diary_rel_path')
-        \ . a:year.'-'.month.'-'.day.vimwiki#vars#get_wikilocal('ext')
+        \ . a:year.'/'.month.'/'.year.'-'.month.'-'.day.vimwiki#vars#get_wikilocal('ext')
   return filereadable(expand(sfile))
 endfunction

The generation of diary wiki looks good, but the index refreshing is not working

@Jaeyong-Cho
Copy link

Jaeyong-Cho commented Sep 15, 2023

It seems like this modification will work.

diff --git a/autoload/vimwiki/diary.vim b/autoload/vimwiki/diary.vim
index b47e6c9..92f8c9e 100644
--- a/autoload/vimwiki/diary.vim
+++ b/autoload/vimwiki/diary.vim
@@ -97,7 +97,7 @@ function! vimwiki#diary#diary_date_link(...) abort
     let l:computed_timestamp = localtime() + l:delta_periods*l:day_s
   endif
 
-  return strftime('%Y-%m-%d', l:computed_timestamp)
+  return strftime('%Y/%m/%Y-%m-%d', l:computed_timestamp)
 
 endfunction
 
@@ -230,7 +230,7 @@ function! vimwiki#diary#get_diary_files() abort
   " Return: <list> diary file names
   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'))
+        \ vimwiki#vars#get_wikilocal('diary_rel_path').'*/*/*'.vimwiki#vars#get_wikilocal('ext'))
   let files = split(s_files, '\n')
   call filter(files, 'fnamemodify(v:val, ":t") =~# "'.escape(rx, '\').'"')
 
@@ -445,8 +445,14 @@ function! vimwiki#diary#generate_diary_section() abort
             let top_link_tpl = link_tpl
           endif
 
+          let my_fl = "__Directory__/__Filename__"
+          let my_fl = substitute(my_fl, "__Filename__", fl, "")
+          let fl = substitute(fl, "-", "/", "")
+          let fl = substitute(fl, "-[0-9][0-9]", "", "")
+          let my_fl = substitute(my_fl, "__Directory__", fl, "")
+
           let bullet = vimwiki#lst#default_symbol().' '
-          let entry = substitute(top_link_tpl, '__LinkUrl__', fl, '')
+          let entry = substitute(top_link_tpl, '__LinkUrl__', my_fl, '')
           let entry = substitute(entry, '__LinkDescription__', topcap, '')
           let wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr')
           let extension = vimwiki#vars#get_wikilocal('ext', wiki_nr)
@@ -463,7 +469,7 @@ function! vimwiki#diary#generate_diary_section() abort
             if empty(subcap)
               continue
             endif
-            let entry = substitute(link_tpl, '__LinkUrl__', fl.'#'.subcap, '')
+            let entry = substitute(link_tpl, '__LinkUrl__', my_fl.'#'.subcap, '')
             let entry = substitute(entry, '__LinkDescription__', subcap, '')
             " if single H1 then depth H2=0, H3=1, H4=2, H5=3, H6=4
             " if multiple H1 then depth H1= 0, H2=1, H3=2, H4=3, H5=4, H6=5
@@ -502,7 +508,7 @@ function! vimwiki#diary#calendar_action(day, month, year, week, dir) abort
   let day = s:prefix_zero(a:day)
   let month = s:prefix_zero(a:month)
 
-  let link = a:year.'-'.month.'-'.day
+  let link = a:year.'/'.month.'/'.year.'-'.month.'-'.day
   if winnr('#') == 0
     if a:dir ==? 'V'
       vsplit
@@ -529,7 +535,7 @@ function! vimwiki#diary#calendar_sign(day, month, year) abort
   let day = s:prefix_zero(a:day)
   let month = s:prefix_zero(a:month)
   let sfile = vimwiki#vars#get_wikilocal('path') . vimwiki#vars#get_wikilocal('diary_rel_path')
-        \ . a:year.'-'.month.'-'.day.vimwiki#vars#get_wikilocal('ext')
+        \ . a:year.'/'.month.'/'.year.'-'.month.'-'.day.vimwiki#vars#get_wikilocal('ext')
   return filereadable(expand(sfile))
 endfunction

@ericsunplus
Copy link
Author

Hi @Jaeyong-Cho , really appreciate your help. I tested with your patch and now index generation and navigation is OK.

I did more test and find that the only remaining issue is C-up (:VimwikiDiaryPrevDay) and C-Down (:VimwikiDiaryNextDay) is not directing me to the correct page.

@Jaeyong-Cho
Copy link

Hi @ericsunplus, this patch will work well.

diff --git a/autoload/vimwiki/diary.vim b/autoload/vimwiki/diary.vim
index b47e6c9..7aa1002 100644
--- a/autoload/vimwiki/diary.vim
+++ b/autoload/vimwiki/diary.vim
@@ -359,13 +359,17 @@ function! vimwiki#diary#goto_next_day() abort
   " Jump to next day
   let link = ''
   let [idx, links] = s:get_position_links(expand('%:t:r'))
+  let my_links = map(vimwiki#diary#get_diary_files(), 'fnamemodify(v:val, ":p:r")')
+  for i in range(0, len(my_links) - 1)
+    let my_links[i] = substitute(my_links[i], s:diary_path(), "", "")
+  endfor
 
   if idx == (len(links) - 1)
     return
   endif
 
   if idx != -1 && idx < len(links) - 1
-    let link = 'diary:'.links[idx+1]
+    let link = 'diary:'.my_links[idx+1]
   else
     " goto today
     let link = 'diary:'.vimwiki#diary#diary_date_link()
@@ -381,13 +385,17 @@ function! vimwiki#diary#goto_prev_day() abort
   " Jump to previous day
   let link = ''
   let [idx, links] = s:get_position_links(expand('%:t:r'))
+  let my_links = map(vimwiki#diary#get_diary_files(), 'fnamemodify(v:val, ":p:r")')
+  for i in range(0, len(my_links) - 1)
+    let my_links[i] = substitute(my_links[i], s:diary_path(), "", "")
+  endfor
 
   if idx == 0
     return
   endif
 
   if idx > 0
-    let link = 'diary:'.links[idx-1]
+    let link = 'diary:'.my_links[idx-1]
   else
     " goto today
     let link = 'diary:'.vimwiki#diary#diary_date_link()

@ericsunplus
Copy link
Author

Hi @Jaeyong-Cho , thank you for all the help. It is now working fine on my side.

And since I am working on windows, there are path sep \ which is causing substitute not working well. A little modification based on your work can fix it

diff --git a/autoload/vimwiki/diary.vim b/autoload/vimwiki/diary.vim
index 7b3be80..ca690ba 100644
--- a/autoload/vimwiki/diary.vim
+++ b/autoload/vimwiki/diary.vim
@@ -361,7 +361,7 @@ function! vimwiki#diary#goto_next_day() abort
   let [idx, links] = s:get_position_links(expand('%:t:r'))
   let my_links = map(vimwiki#diary#get_diary_files(), 'fnamemodify(v:val, ":p:r")')
   for i in range(0, len(my_links) - 1)
-    let my_links[i] = substitute(my_links[i], s:diary_path(), "", "")
+    let my_links[i] = substitute(substitute(my_links[i], "\\", "\/", "g"), substitute(s:diary_path(), "\\", "\/", "g"), "", "")
   endfor
 
   if idx == (len(links) - 1)
@@ -387,7 +387,7 @@ function! vimwiki#diary#goto_prev_day() abort
   let [idx, links] = s:get_position_links(expand('%:t:r'))
   let my_links = map(vimwiki#diary#get_diary_files(), 'fnamemodify(v:val, ":p:r")')
   for i in range(0, len(my_links) - 1)
-    let my_links[i] = substitute(my_links[i], s:diary_path(), "", "")
+    let my_links[i] = substitute(substitute(my_links[i], "\\", "\/", "g"), substitute(s:diary_path(), "\\", "\/", "g"), "", "")
   endfor
 
   if idx == 0

To be honest this is my first time touching inside vimscript. You really shed the light for me. Big appreciations!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants