Skip to content
Permalink
Browse files

add template files and update images

  • Loading branch information...
smit1678 committed May 31, 2019
1 parent d635b23 commit 0bb4ac65508ffeda9de134665fa5dfb26ded8257
Showing with 1,352 additions and 150 deletions.
  1. +133 −0 .build_scripts/build_index.js
  2. +110 −0 .build_scripts/clean.py
  3. +153 −0 .circleci/config.yml
  4. +4 −0 .gitignore
  5. +3 −0 .gitmodules
  6. +3 −0 .vscode/settings.json
  7. +13 −0 Pipfile
  8. +60 −0 Pipfile.lock
  9. +294 −1 README.md
  10. +6 −0 archetypes/default.md
  11. +133 −0 build_index.js
  12. +110 −0 clean.py
  13. +15 −0 config.toml
  14. +153 −0 config.yml
  15. +2 −2 00-executive-summary.md → content/_index.md
  16. BIN content/images/Technical-Guidelines0.png
  17. BIN content/images/Technical-Guidelines1.png
  18. BIN content/images/Technical-Guidelines10.jpg
  19. BIN content/images/Technical-Guidelines11.jpg
  20. BIN content/images/Technical-Guidelines11a.jpg
  21. BIN content/images/Technical-Guidelines12.jpg
  22. BIN content/images/Technical-Guidelines13.jpg
  23. BIN content/images/Technical-Guidelines14.png
  24. BIN content/images/Technical-Guidelines15.jpg
  25. BIN content/images/Technical-Guidelines16.png
  26. BIN content/images/Technical-Guidelines17.png
  27. BIN content/images/Technical-Guidelines2.png
  28. BIN content/images/Technical-Guidelines3.jpg
  29. BIN content/images/Technical-Guidelines4.png
  30. BIN content/images/Technical-Guidelines5.png
  31. BIN content/images/Technical-Guidelines6.png
  32. BIN content/images/Technical-Guidelines6a.jpg
  33. BIN content/images/Technical-Guidelines7.png
  34. BIN content/images/Technical-Guidelines8.png
  35. BIN content/images/Technical-Guidelines9.jpg
  36. BIN content/images/cover.png
  37. BIN content/images/image1.png
  38. BIN content/images/image12.png
  39. BIN content/images/image3.png
  40. BIN content/images/uav-chart-map.jpg
  41. +3 −35 00-cover-toc.md → content/pages/00-acknowlegements-abbreviations.md
  42. +6 −21 { → content/pages}/01-objective.md
  43. +1 −1 { → content/pages}/02-uavs-as-a-game-changer-for-pics.md
  44. +2 −2 { → content/pages}/03-securing-uav-flight.md
  45. +2 −7 { → content/pages}/04-determining-whether-the-uav.md
  46. +5 −7 { → content/pages}/05-choosing-the-right-uav.md
  47. +1 −1 { → content/pages}/06-choosing-the-sensor.md
  48. +8 −31 { → content/pages}/07-preparing-for-the-uav-mission.md
  49. +3 −12 { → content/pages}/08-managing-work-flow.md
  50. +2 −13 { → content/pages}/09-after-the-flight.md
  51. +1 −1 { → content/pages}/10-handling-project-management.md
  52. +3 −13 { → content/pages}/11-case-study.md
  53. +1 −2 { → content/pages}/12-conclusions.md
  54. 0 { → content/pages}/annex-1.md
  55. +1 −1 { → content/pages}/footnotes.md
  56. +89 −0 package-lock.json
  57. +26 −0 package.json
  58. +1 −0 resources/_gen/assets/scss/book.scss_48b060fe05b0a273d182ef83c0605941.content
  59. +1 −0 resources/_gen/assets/scss/book.scss_48b060fe05b0a273d182ef83c0605941.json
  60. +3 −0 settings.json
  61. +1 −0 themes/book
@@ -0,0 +1,133 @@
const fs = require("fs");
const path = require("path");

const lunr = require("lunr");
const matter = require("gray-matter");
const toml = require("toml");

const langs = ["da", "de", "en", "es", "fi", "fr", "hu", "it", "ja", "jp", "nl", "no", "pt", "ro", "ru", "sv", "th", "tr"];
const config = fs.readFileSync("./config.toml", "utf8");
const data = toml.parse(config)
const defaultLang = data.DefaultContentLanguage;
let siteLangs = [];
for ( const language in data.languages) {
siteLangs.push(language.toString());
}
if (siteLangs.indexOf(defaultLang) == -1) {
siteLangs.push(defaultLang);
}

if (siteLangs.length > 1) {
/* multiple languages */
for (lang of siteLangs) {
let dir = path.join(__dirname, "../content");
if (langs.indexOf(lang) != -1) {
dir = path.join(dir, lang)
if (lang == defaultLang) {
lang = '.';
}
else {
lang = `.${lang}`;
}
walk(dir).then((foldersContents)=>{
const documents = foldersContents.filter(filterMd).filter(filterEmpty).map(readFile);
const idx = lunr(function() {
this.ref('id');
this.field('content');
documents.forEach(function (doc) {
this.add(doc)
}, this)
});
const lunrDocs = documents.map((obj) => {
return {id: obj.id, path: obj.path, title: obj.title}
})
fs.writeFile(`./static/lunr-documents${lang}.json`, JSON.stringify(lunrDocs), () => {
console.log(`lunr-documents${lang}.json written`);
});

fs.writeFile(`./static/lunr-index${lang}.json`, JSON.stringify(idx), () => {
console.log(`lunr-index${lang}.json written`);
});
});
}
}
} else {
/* single language */
if (langs.indexOf(siteLangs[0]) != -1) {
let dir = path.join(__dirname, "../content"); walk(dir).then((foldersContents)=>{
const documents = foldersContents.filter(filterMd).filter(filterEmpty).map(readFile);
const idx = lunr(function() {
this.ref('id');
this.field('content');
documents.forEach(function (doc) {
this.add(doc)
}, this)
});
const lunrDocs = documents.map((obj) => {
return {id: obj.id, path: obj.path, title: obj.title}
})
fs.writeFile(`./static/lunr-documents.json`, JSON.stringify(lunrDocs), () => {
console.log("lunr documents written");
});

fs.writeFile(`./static/lunr-index.json`, JSON.stringify(idx), () => {
console.log("lunr index written");
});
});
}
}

function walk(dir) {
return new Promise((resolve, reject) => {
fs.readdir(dir, (error, files) => {
if (error) {
return reject(error);
}
Promise.all(files.map((file) => {
return new Promise((resolve, reject) => {
const filepath = path.join(dir, file);
fs.stat(filepath, (error, stats) => {
if (error) {
return reject(error);
}
if (stats.isDirectory()) {
walk(filepath).then(resolve);
} else if (stats.isFile()) {
resolve(filepath);
}
});
});
}))
.then((foldersContents) => {
resolve(foldersContents.reduce((all, folderContents) => all.concat(folderContents), []));
});
});
});
}

function filterMd(filepath) {
const ext = path.extname(filepath)
if (ext == ".md") {
return filepath
}
}

function filterEmpty(filepath) {
const str = fs.readFileSync(filepath, "utf8")
const content = matter(str).content;
if (content) {
return filepath
}
}

function readFile(filepath, index) {
const str = fs.readFileSync(filepath, "utf8")
const title = matter(str).data.title || filepath.split("/").pop() || "introduction";
let path = filepath.split("content").pop()
path = path.replace(".md", "/")
path = path.toLowerCase()
if (path.split("/").pop() == "_index.html") {
path = path.slice(0,-9);
}
return {id: index, path: path, title: title, content: matter(str).content}
}
@@ -0,0 +1,110 @@
import os
import re
from shutil import copyfile

import frontmatter
import toml


def main():
extensions = {}
with open('config.toml', 'r') as f:
config = toml.loads(f.read())
default_lang = config['DefaultContentLanguage']
site_name = config['title'].replace(' ', '_')
site_name = site_name.replace("'", "")
site_name = site_name.replace('"', '')
site_name = site_name.replace(',', '')
site_name = site_name.replace('.', '')
if 'languages' in config:
for key in config['languages']:
extensions[config['languages'][key]['contentDir'].split('/')[-1]] = key
if key != default_lang:
os.mkdir(os.path.join('pdf-build', key))
guides = []
if 'pages' in os.listdir('content'):
# single language
contents = []
for item in os.listdir('content'):
if os.path.isfile(os.path.join('content',item)):
ext = os.path.splitext(item)[1]
if ext != '.md':
copyfile(os.path.join('content', item), os.path.join('pdf-build',item))
# move image files
for path, _, files in os.walk('content/pages'):
for filename in files:
ext = os.path.splitext(filename)[1]
if ext != '.md':
copyfile(os.path.join(path, filename), os.path.join('pdf-build',filename))
images = [f for f in os.listdir('pdf-build') if re.search(r'.*\.(jpe?g|png|gif)$', f)]
for path, _, files in os.walk('content/pages'):
for filename in files:
ext = os.path.splitext(filename)[1]
if ext == '.md':
content = clean_markdown(path, filename, images, default_lang=default_lang)
if content:
contents.append({'name':filename, 'content': content})
else:
continue
full_pdf_content = ""
content = clean_markdown("content", "_index.md", images)
if content:
full_pdf_content += content
full_pdf_content += "\n\n\pagebreak\n\n"
for item in sorted(contents, key=lambda k: k['name']):
full_pdf_content += item['content']
full_pdf_content += "\n\n\pagebreak\n\n"
with open('pdf-build/' + site_name + ".md", 'w') as f:
f.write(full_pdf_content)

else:
# multiple languages
for lang in os.listdir('content'):
contents = []
lang_key = extensions[lang]
lang_path = os.path.join('content', lang)
for path, _, files in os.walk(lang_path):
if lang_key == default_lang:
lang_key = ''
for filename in files:
ext = os.path.splitext(filename)[1]
if ext == '.md':
content = clean_markdown(path, filename, lang_key ,default_lang)
if content:
contents.append({'name':filename, 'content': content})
else:
copyfile(os.path.join(path,filename), os.path.join('pdf-build',lang_key,filename))
full_pdf_content = ""
for item in sorted(contents, key=lambda k: k['name']):
full_pdf_content += item['content']
full_pdf_content += "\n\n\pagebreak\n\n"
with open('pdf-build/' + site_name + ".md", 'w') as f:
f.write(full_pdf_content)


def clean_markdown(path, filename, images, lang="", default_lang = "en"):
post = frontmatter.load(os.path.join(path, filename))
if post.content:
title = post.metadata.get('title', '')
guide = {}
guide['filename'] = filename
content = post.content
for image in images:
replace_regex = r'(\!\[.*\]).*(\().*\/(' + re.escape(image) + r')([A-Za-z\s\"\'\-\,\.\;\:]*)(\))'
print(replace_regex)
content = re.sub(replace_regex, r'\1\2\3\5', content)
guide['content'] = ''
if title:
guide['content'] += '# {0} \n\n'.format(title)
guide['content'] += content
if lang and lang != default_lang:
out_file = os.path.join('pdf-build', lang, guide['filename'])
else:
out_file = os.path.join('pdf-build', guide['filename'])
with open(out_file, 'w') as f:
f.write(guide['content'])
return guide['content']
return ''

if __name__ == "__main__":
main()

0 comments on commit 0bb4ac6

Please sign in to comment.
You can’t perform that action at this time.