Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Commit

Permalink
circle: new apidoc building & theme
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Feb 5, 2018
1 parent cecce64 commit d10af0a
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 4 deletions.
83 changes: 83 additions & 0 deletions .circleci/build-apidoc.js
@@ -0,0 +1,83 @@
let fs = require('fs');
let path = require('path');
let markdownit = require('./markdown-it')({
html: true
});

var defaultRender = markdownit.renderer.rules.link_open || function(tokens, idx, options, env, self) {
return self.renderToken(tokens, idx, options);
};

markdownit.renderer.rules.link_open = function (tokens, idx, options, env, self) {
let aIndex = tokens[idx].attrIndex('href');
if (aIndex >= 0) {
let attribute = tokens[idx].attrs[aIndex][1];
if (attribute.substring(attribute.length - 3) === '.md') {
tokens[idx].attrs[aIndex][1] = attribute.substring(0, attribute.length - 3) + ".html";
}
}

return defaultRender(tokens, idx, options, env, self);
};

let rootDir = process.argv[2]

processDir(rootDir, "");

function processDir(root, diffPath) {
let path = root + "/" + diffPath;
console.log("Processing dir " + path);
fs.readdir(path, function (err, files) {
files.forEach(function (file, index) {
let filePath = path + "/" + file;
let stat = fs.statSync(filePath);
if (stat.isDirectory()) {
processDir(root, diffPath + "/" + file);
} else if (stat.isFile()) {
processFile(root, diffPath, file);
}
});
});
}

function processFile(root, diffPath, file) {
if (file.substring(file.length - 3) !== '.md') {
return;
}

let filename = root + "/" + diffPath + "/" + file;
console.log("Processing file " + filename);
let data = fs.readFileSync(filename, {encoding: 'utf-8'});

let titleRegexp = /^(?:#{1,3})\s+(.+)$/gm;
let title = (titleRegexp.exec(data) || [null, "Sygic Travel SDK"])[1];
let upCount = (diffPath.match(/\//g) || []).length;
let up = "../".repeat(upCount);
let output = `<html>
<head>
<link rel="stylesheet" href="${up}style.css">
<title>${title}</title>
<style>
body { margin: 0; padding: 0; }
div.header { background: #0366d6; color: white; padding: 10px 20px; }
div.header a { color: white; }
div.header h1 { border-bottom: none; margin: 0; padding: 0; }
div.content { padding: 20px; }
</style>
</head>
<body>
<div class="markdown-body">
<div class="header">
<a style="float: right;" href="https://github.com/sygic-travel/android-sdk">GitHub repository</a>
<h1><a href="${up}">Sygic Travel Android SDK</a></h1>
</div>
<div class="content">
` +
markdownit.render(data)
+ `</div></div>
</body>
</html>`;

let outputFilename = filename.substring(0, filename.length - 2) + "html";
fs.writeFileSync(outputFilename, output, {encoding: 'utf-8'});
}
9 changes: 6 additions & 3 deletions .circleci/config.yml
Expand Up @@ -3,7 +3,7 @@ jobs:
build:
working_directory: ~/android-sdk
docker:
- image: circleci/android:api-26-alpha
- image: sygictravel/android-docker-build
steps:
- checkout
- restore_cache:
Expand Down Expand Up @@ -39,16 +39,19 @@ jobs:
command: |
if [[ $CIRCLE_BRANCH = "master" ]] || [[ ! -z $CIRCLE_TAG ]]; then
./gradlew dokka
cp /sdk-build/markdown-it.js ./.circleci/markdown-it.js
cp /sdk-build/apidoc-style.css ./build/dokkaDoc/sdk/style.css
node ./.circleci/build-apidoc.js ./build/dokkaDoc/sdk
fi
- run:
name: Upload Documentation
command: |
if [[ $CIRCLE_BRANCH = "master" ]] || [[ ! -z $CIRCLE_TAG ]]; then
DOC_PATH="s3://docs.sygictravelapi.com/android-sdk/master"
if [[ ! -z $CIRCLE_TAG ]]; then
DOC_PATH="s3://docs.sygictravelapi.com/android-sdk/$CIRCLE_TAG"
DOC_PATH="s3://docs.sygictravelapi.com/android-sdk/${CIRCLE_TAG:1}"
fi
aws s3 sync ./sdk/build/dokkaDoc $DOC_PATH --delete --acl public-read
aws s3 sync ./build/dokkaDoc/sdk $DOC_PATH --delete --acl public-read
fi
- run:
name: Upload SDK to Bintray
Expand Down
2 changes: 1 addition & 1 deletion dokka.gradle
@@ -1,7 +1,7 @@
apply plugin: 'org.jetbrains.dokka-android'

dokka {
outputFormat = 'html'
outputFormat = 'gfm'
outputDirectory = "$buildDir/dokkaDoc"
// includes = ['../README.md']
skipDeprecated = true
Expand Down

0 comments on commit d10af0a

Please sign in to comment.