diff --git a/build.js b/build.js index 31b80cc..2d9fef0 100644 --- a/build.js +++ b/build.js @@ -20,14 +20,18 @@ const l10n = { author: 'Sergey Konstantinov', chapter: 'Chapter', toc: 'Table of Contents', - frontPage: 'Front Page' + frontPage: 'Front Page', + description: "Designing APIs is a very special skill: API is a multiplier to both your opportunities and mistakes. This book is written to share the expertise and describe the best practices in the API design. The book comprises three large sections. In Section I we'll discuss designing APIs as a concept: how to build the architecture properly, from a high-level planning down to final interfaces. Section II is dedicated to an API's lifecycle: how interfaces evolve over time, and how to elaborate the product to match users' needs. Finally, Section III is more about un-engineering sides of the API, like API marketing, organizing support, and working with a community.", + locale: 'en_US' }, ru: { title: 'API', author: 'Сергей Константинов', chapter: 'Глава', toc: 'Содержание', - frontPage: 'Титульный лист' + frontPage: 'Титульный лист', + description: 'Разработка API — особый навык: API является как мультипликатором ваших возможностей, так и мультипликатором ваших ошибок. Эта книга написана для того, чтобы поделиться опытом и изложить лучшие практики проектирования API. Книга состоит из трёх больших разделов. В первом разделе мы поговорим о проектировании API на стадии разработки концепции — как грамотно выстроить архитектуру, от крупноблочного планирования до конечных интерфейсов. Второй раздел будет посвящён жизненному циклу API — как интерфейсы эволюционируют со временем и как развивать продукт так, чтобы отвечать потребностям пользователей. Наконец, третий раздел будет касаться больше не-разработческих сторон жизни API — поддержки, маркетинга, работы с комьюнити.', + locale: 'ru_RU' } }; const css = fs.readFileSync('src/style.css', 'utf-8'); @@ -55,27 +59,47 @@ function buildDocs (langsToBuild, targets, l10n) { } function buildDoc (lang, targets, l10n) { + const pageBreak = '
'; const structure = getStructure({ path: `./src/${lang}/clean-copy/`, l10n, - pageBreak:'
' + pageBreak }); + const tableOfContents = `${pageBreak}`; + const getRef = (anchor) => { + return ``; + } const htmlContent = [ structure.frontPage, + tableOfContents, ...structure.sections .map((section) => section.chapters.reduce((content, chapter) => { if (chapter.title) { - content.push(`

${chapter.title}

`); + content.push(`

${getRef(chapter.anchor)}${chapter.title}

`); } content.push(chapter.content); return content; - }, [section.title ? `

${section.title}

` : '']).join('')) + }, [section.title ? `

${getRef(section.anchor)}${section.title}

` : '']).join('')) ].join('\n'); const html = ` ${l10n.author}. ${l10n.title} + + + + + + @@ -102,10 +126,11 @@ function getStructure ({ path, l10n: { chapter }, pageBreak}) { fs.readdirSync(path) .filter((p) => fs.statSync(`${path}${p}`).isDirectory()) .sort() - .forEach((dir) => { + .forEach((dir, index) => { const name = dir.split('-')[1]; const section = { title: name, + anchor: `section-${index + 1}`, chapters: [] } @@ -117,9 +142,11 @@ function getStructure ({ path, l10n: { chapter }, pageBreak}) { const md = fs.readFileSync(`${subdir}${file}`, 'utf-8').trim(); const [ title, ...paragraphs ] = md.split(/\r?\n/); section.chapters.push({ - title: title.replace(/^### /, `${chapter} ${counter++}. `), + anchor: `chapter-${counter}`, + title: title.replace(/^### /, `${chapter} ${counter}. `), content: mdHtml.makeHtml(paragraphs.join('\n')) + pageBreak }); + counter++; }); structure.sections.push(section); diff --git a/docs/API.en.epub b/docs/API.en.epub index 34f47cb..4548422 100644 Binary files a/docs/API.en.epub and b/docs/API.en.epub differ diff --git a/docs/API.en.html b/docs/API.en.html index c3c98a1..5deaa6b 100644 --- a/docs/API.en.html +++ b/docs/API.en.html @@ -2,6 +2,12 @@ Sergey Konstantinov. The API + + + + + +