Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7404a3f

Browse files
feylethAlexis Ronez
authored andcommitted
add generation for multy language
1 parent 2aba938 commit 7404a3f

50 files changed

Lines changed: 114 additions & 1700 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build_ebook.py

Lines changed: 74 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,70 +3,94 @@
33
import os
44
import re
55

6-
# Recursively gather all markdown files in the right order
7-
markdownFiles = []
86

9-
for root, subdirs, files in os.walk('.'):
10-
for fn in files:
11-
if 'md' in fn and 'ebook.md' not in fn:
12-
path = os.path.join(root, fn)
7+
def create_ebook(path):
138

14-
# "02_Development_environment.md" -> "Development environment"
15-
title = fn.split('.')[0] # "02_Development_environment.md" -> "02_Development_environment"
16-
title = title.replace('_', ' ') # "02_Development_environment" -> "02 Development environment"
17-
title = ' '.join(title.split(' ')[1:]) # "02 Development environment" -> "Development environment"
9+
name_path = path
10+
print('create \"' + name_path + '\" ebook')
11+
# Recursively gather all markdown files in the right order
12+
markdownFiles = []
1813

19-
with open(path, 'r') as f:
20-
markdownFiles.append({
21-
'title': title,
22-
'filename': os.path.join(root, fn),
23-
'contents': f.read()
24-
})
14+
for root, subdirs, files in os.walk(name_path):
15+
for fn in files:
16+
if 'md' in fn and 'ebook.md' not in fn:
17+
path = os.path.join(root, fn)
2518

26-
markdownFiles.sort(key=lambda entry: entry['filename'])
19+
# "02_Development_environment.md" -> "Development environment"
20+
# "02_Development_environment.md" -> "02_Development_environment"
21+
title = fn.split('.')[0]
22+
# "02_Development_environment" -> "02 Development environment"
23+
title = title.replace('_', ' ')
24+
# "02 Development environment" -> "Development environment"
25+
title = ' '.join(title.split(' ')[1:])
2726

28-
# Create concatenated document
29-
print('processing markdown...')
27+
with open(path, 'r') as f:
28+
markdownFiles.append({
29+
'title': title,
30+
'filename': os.path.join(root, fn),
31+
'contents': f.read()
32+
})
3033

31-
allMarkdown = ''
34+
markdownFiles.sort(key=lambda entry: entry['filename'])
3235

33-
for entry in markdownFiles:
34-
contents = entry['contents']
36+
# Create concatenated document
37+
print('processing markdown...')
3538

36-
# Add title
37-
contents = '# ' + entry['title'] + '\n\n' + contents
39+
allMarkdown = ''
40+
41+
for entry in markdownFiles:
42+
contents = entry['contents']
43+
44+
# Add title
45+
contents = '# ' + entry['title'] + '\n\n' + contents
46+
47+
# Fix image links
48+
contents = re.sub(r'\/images\/', 'images/', contents)
49+
contents = re.sub(r'\.svg', '.png', contents)
50+
51+
# Fix remaining relative links (e.g. code files)
52+
contents = re.sub(
53+
r'\]\(\/', '](https://vulkan-tutorial.com/', contents)
54+
55+
# Fix chapter references
56+
def repl(m):
57+
target = m.group(1)
58+
target = target.lower()
59+
target = re.sub('_', '-', target)
60+
target = target.split('/')[-1]
61+
62+
return '](#' + target + ')'
3863

39-
# Fix image links
40-
contents = re.sub(r'\/images\/', 'images/', contents)
41-
contents = re.sub(r'\.svg', '.png', contents)
64+
contents = re.sub(r'\]\(!([^)]+)\)', repl, contents)
4265

43-
# Fix remaining relative links (e.g. code files)
44-
contents = re.sub(r'\]\(\/', '](https://vulkan-tutorial.com/', contents)
66+
allMarkdown += contents + '\n\n'
4567

46-
# Fix chapter references
47-
def repl(m):
48-
target = m.group(1)
49-
target = target.lower()
50-
target = re.sub('_', '-', target)
51-
target = target.split('/')[-1]
68+
# Add title
69+
dateNow = datetime.datetime.now()
70+
71+
metadata = '% Vulkan Tutorial\n'
72+
metadata += '% Alexander Overvoorde\n'
73+
metadata += '% ' + dateNow.strftime('%B %Y') + '\n\n'
5274

53-
return '](#' + target + ')'
75+
allMarkdown = metadata + allMarkdown
5476

55-
contents = re.sub(r'\]\(!([^)]+)\)', repl, contents)
77+
with open('ebook.md', 'w') as f:
78+
f.write(allMarkdown)
5679

57-
allMarkdown += contents + '\n\n'
80+
# Building PDF
81+
print('building pdf...')
5882

59-
# Add title
60-
dateNow = datetime.datetime.now()
83+
subprocess.check_output(['pandoc', 'ebook.md', '-V', 'documentclass=report', '-t', 'latex', '-s',
84+
'--toc', '--listings', '-H', 'ebook/listings-setup.tex', '-o', 'ebook/Vulkan Tutorial ' + name_path + '.pdf', '--pdf-engine=xelatex'])
6185

62-
metadata = '% Vulkan Tutorial\n'
63-
metadata += '% Alexander Overvoorde\n'
64-
metadata += '% ' + dateNow.strftime('%B %Y') + '\n\n'
86+
print('building epub...')
6587

66-
allMarkdown = metadata + allMarkdown
88+
subprocess.check_output(
89+
['pandoc', 'ebook.md', '--toc', '-o', 'ebook/Vulkan Tutorial ' + name_path + '.epub'])
90+
91+
# Clean up
92+
os.remove('ebook.md')
6793

68-
with open('ebook.md', 'w') as f:
69-
f.write(allMarkdown)
7094

7195
# Convert all SVG images to PNG for pandoc
7296
print('converting svgs...')
@@ -77,20 +101,12 @@ def repl(m):
77101
parts = fn.split('.')
78102

79103
if parts[1] == 'svg':
80-
subprocess.check_output(['inkscape', '-z', '-e', 'images/' + parts[0] + '.png', 'images/' + fn], stderr=subprocess.STDOUT)
104+
subprocess.check_output(['inkscape', '-z', '-e', 'images/' +
105+
parts[0] + '.png', 'images/' + fn], stderr=subprocess.STDOUT)
81106
generatedPngs.append('images/' + parts[0] + '.png')
82107

83-
# Building PDF
84-
print('building pdf...')
85-
86-
subprocess.check_output(['pandoc', 'ebook.md', '-V', 'documentclass=report', '-t', 'latex', '-s', '--toc', '--listings', '-H', 'ebook/listings-setup.tex', '-o', 'ebook/Vulkan Tutorial.pdf'])
87-
88-
print('building epub...')
89-
90-
subprocess.check_output(['pandoc', 'ebook.md', '--toc', '-o', 'ebook/Vulkan Tutorial.epub'])
91-
92-
# Clean up
93-
os.remove('ebook.md')
108+
create_ebook('en')
109+
create_ebook('fr')
94110

95111
for fn in generatedPngs:
96112
os.remove(fn)

config.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
}
2929
},
3030
"ignore": {
31-
"files": ["README.md"]
31+
"files": ["README.md", "build_ebook.py"],
32+
"folders": ["ebook"]
3233
},
34+
"languages": {"en": "English", "fr": "French"},
35+
"language": "en",
3336
"processor": "VulkanLinkProcessor"
3437
}
Lines changed: 1 addition & 1 deletion

01_Overview.md renamed to en/01_Overview.md

Lines changed: 1 addition & 1 deletion
Lines changed: 7 additions & 7 deletions

03_Drawing_a_triangle/00_Setup/00_Base_code.md renamed to en/03_Drawing_a_triangle/00_Setup/00_Base_code.md

Lines changed: 1 addition & 1 deletion

03_Drawing_a_triangle/00_Setup/01_Instance.md renamed to en/03_Drawing_a_triangle/00_Setup/01_Instance.md

Lines changed: 1 addition & 1 deletion

03_Drawing_a_triangle/00_Setup/02_Validation_layers.md renamed to en/03_Drawing_a_triangle/00_Setup/02_Validation_layers.md

Lines changed: 2 additions & 2 deletions

03_Drawing_a_triangle/00_Setup/03_Physical_devices_and_queue_families.md renamed to en/03_Drawing_a_triangle/00_Setup/03_Physical_devices_and_queue_families.md

Lines changed: 1 addition & 1 deletion

03_Drawing_a_triangle/00_Setup/04_Logical_device_and_queues.md renamed to en/03_Drawing_a_triangle/00_Setup/04_Logical_device_and_queues.md

0 commit comments

Comments
 (0)