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

generate html in parallel #999

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
run: |
cd work
# Create html documents
make html
make -j4 html2

cd ..
- name: Lock mutex
Expand Down
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
SRC_JAX := $(wildcard doc/*.jax vim_faq/*.jax)
OUT_JAX := $(addprefix target/html/doc/,$(notdir $(SRC_JAX)))
TAGS_JAX := target/html/doc/tags.jax
HTML := $(OUT_JAX:.jax=.html) $(TAGS_JAX:.jax=.html)

.PHONY: all check replace html clean
.PHONY: html2 tags

all:

Expand All @@ -15,5 +21,25 @@ html:
cp doc/*.jax vim_faq/*.jax target/html/doc
-cd target/html/doc ; vim -eu ../../../tools/buildhtml.vim -c "qall!"

html2: $(HTML)

tags: $(TAGS_JAX)

target/html/doc/%.jax: doc/%.jax
-@mkdir -p target/html/doc
cp $< $@

target/html/doc/%.jax: vim_faq/%.jax
-@mkdir -p target/html/doc
cp $< $@

$(TAGS_JAX): $(OUT_JAX)
rm -f $@
-cd target/html/doc ; vim -eu ../../../tools/build_tag.vim -c "qall!"

target/html/doc/%.html: target/html/doc/%.jax $(TAGS_JAX)
-@mkdir -p target/html/doc
-cd target/html/doc ; vim -eu ../../../tools/build_html.vim $(notdir $(<F)) $(notdir $@) -c "qall!"

clean:
rm -rf target
68 changes: 68 additions & 0 deletions tools/build_html.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
set nocompatible
set nomore
set encoding=utf-8
set fileencodings=utf-8
syntax on
colorscheme delek
let g:html_no_progress = 1

if has('windows') && !has('gui_running')
set t_ti=
endif

enew!

source <sfile>:h/tag_aliases.vim
source <sfile>:h/untranslated.vim
source <sfile>:h/makehtml.vim

let s:tools_dir = expand('<sfile>:p:h')
let s:proj_dir = expand('<sfile>:p:h:h')

function! s:main()
" for the lastest help syntax
let &runtimepath = s:tools_dir . ',' . &runtimepath
" for ja custom syntax
let &runtimepath .= ',' . s:proj_dir
if argc() != 2
echoerr "require two arguments"
finish
endif
call s:BuildHtml(argv(0), argv(1))
endfunction

function! s:BuildHtml(src, dst)
call MakeHtml2(a:src, a:dst, 1)
call s:ToJekyll(a:dst)
endfunction

function! s:ToJekyll(file)
set nomodeline
execute "edit! " . a:file
set fileformat=unix

let helpname = expand('%:t:r')
if helpname == 'index'
let helpname = 'help'
endif

" remove header
silent 1,/^<hr>/delete _
" remove footer
silent /^<hr>/,$delete _

" escape jekyll tags
silent %s/{\{2,}\|{%/{{ "\0" }}/ge

" YAML front matter
call append(0, [
\ '---',
\ 'layout: vimdoc',
\ printf("helpname: '%s'", helpname),
\ '---',
\ ])

update!
endfunction

call s:main()
40 changes: 40 additions & 0 deletions tools/build_tag.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
set nocompatible
set nomore
set encoding=utf-8
set fileencodings=utf-8
syntax on
colorscheme delek
let g:html_no_progress = 1

if has('windows') && !has('gui_running')
set t_ti=
endif

enew!

source <sfile>:h/tag_aliases.vim
source <sfile>:h/untranslated.vim
source <sfile>:h/makehtml.vim

let s:tools_dir = expand('<sfile>:p:h')
let s:proj_dir = expand('<sfile>:p:h:h')

function! s:main()
" for the lastest help syntax
let &runtimepath = s:tools_dir . ',' . &runtimepath
" for ja custom syntax
let &runtimepath .= ',' . s:proj_dir
call s:BuildTag()
endfunction

function! s:BuildTag()
" generate tags
try
helptags .
catch
echo v:exception
endtry
call MakeTagsFile()
endfunction

call s:main()
46 changes: 31 additions & 15 deletions tools/makehtml.vim
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ function! MakeHtmlAll(...)
endif
endfunction

function! s:JsonName(lang)
return a:lang == "" ? "tags.json" : printf("tags-%s.json", a:lang)
endfunction

function! MakeTagsFile()
let files = split(glob('tags'), '\n')
let files += split(glob('tags-??'), '\n')
Expand All @@ -50,7 +54,7 @@ function! MakeTagsFile()
endif
silent new `=fname`
silent %delete _
let tags = s:GetTags(lang)
let tags = s:LoadTags(lang)
for tagname in sort(keys(tags))
if tagname == "help-tags"
continue
Expand All @@ -60,6 +64,8 @@ function! MakeTagsFile()
call append('$', ' vim:ft=help:')
silent 1delete _
silent wq!
" save JSON tag cache
call writefile([js_encode(tags)], s:JsonName(lang), "s")
endfor
endfunction

Expand Down Expand Up @@ -216,26 +222,36 @@ endfunction

function! s:GetTags(lang)
if !exists("s:tags_" . a:lang)
let &l:tags = (a:lang == "") ? "./tags" : "./tags-" . a:lang
let tags = {}
for item in taglist(".*")
let item["html"] = s:HtmlName(item["filename"])
let tags[item["name"]] = item
endfor
" for help-tags
let item = {}
let item["name"] = "help-tags"
if s:IsSingleMode()
let item["html"] = "tags.html"
" try to load JSON tag cache
let jsonname = s:JsonName(a:lang)
if filereadable(jsonname)
let s:tags_{a:lang} = js_decode(readfile(jsonname)[0])
else
let item["html"] = printf("tags%s.html", (a:lang == "") ? "" : "." . a:lang)
let s:tags_{a:lang} = s:LoadTags(a:lang)
endif
let tags[item["name"]] = item
let s:tags_{a:lang} = tags
endif
return s:tags_{a:lang}
endfunction

func s:LoadTags(lang)
let &l:tags = (a:lang == "") ? "./tags" : "./tags-" . a:lang
let tags = {}
for item in taglist(".*")
let item["html"] = s:HtmlName(item["filename"])
let tags[item["name"]] = item
endfor
" for help-tags
let item = {}
let item["name"] = "help-tags"
if s:IsSingleMode()
let item["html"] = "tags.html"
else
let item["html"] = printf("tags%s.html", (a:lang == "") ? "" : "." . a:lang)
endif
let tags[item["name"]] = item
return tags
endfunction

function! s:IsSingleMode()
" if there is one language files, do not append language identifier
" (use "help.html" instead of "help.ab.html").
Expand Down