Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkfranz committed Sep 11, 2023
1 parent 06cf331 commit 197f4c5
Show file tree
Hide file tree
Showing 7 changed files with 1,263 additions and 627 deletions.
8 changes: 6 additions & 2 deletions demos/edge-arrows/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
{ "data": { "id": "n19" } },
{ "data": { "id": "e9", "source": "n18", "target": "n19", "arrow": "diamond" } },

{ "data": { "id": "n20", "type": "none" } },
{ "data": { "id": "n20", "type": "chevron" } },
{ "data": { "id": "n21" } },
{ "data": { "id": "e10", "source": "n20", "target": "n21", "arrow": "none" } }
{ "data": { "id": "e10", "source": "n20", "target": "n21", "arrow": "chevron" } },

{ "data": { "id": "n22", "type": "none" } },
{ "data": { "id": "n23" } },
{ "data": { "id": "e11", "source": "n22", "target": "n23", "arrow": "none" } }
]
104 changes: 102 additions & 2 deletions docmaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ let Handlebars = require('handlebars');
let jsonlint = require('jsonlint');
let hljs = require('highlight.js');
let encoding = 'utf8';
let config;
let config, versions;
let configFile = './docmaker.json';
let mdRend = new marked.Renderer();
let path = require('path');
let versionFile = './versions.json';

let rendCode = mdRend.code;
mdRend.code = function(code, lang){
Expand All @@ -25,6 +26,9 @@ mdRend.code = function(code, lang){
try {
jsonlint.parse( fs.readFileSync( path.join(__dirname, configFile), 'utf8') ); // validate first for convenience
config = require( configFile );

jsonlint.parse( fs.readFileSync( path.join(__dirname, versionFile), 'utf8') ); // validate first for convenience
versions = require( versionFile );
} catch(e){
console.error('\n`' + configFile + '` could not be read; check the JSON is formatted correctly via jsonlint');
throw e;
Expand Down Expand Up @@ -83,6 +87,18 @@ function md2html( file ){
return html;
}

function templateToHtml(context) {
if (context.mdTemplate === "intro") {
generate_versions(context);
}

let introHtmlTemplate = md2html(context.mdTemplate);
let introTemplate = Handlebars.compile(introHtmlTemplate);
let infoHtml = introTemplate(context);
let html = marked.parse(infoHtml);
return html;
}

function toUrl( str ){
str = str || '';
str = str.replace(/ /g, '-');
Expand Down Expand Up @@ -177,6 +193,14 @@ function compileConfig( config ){
for( let i = 0; sections && i < sections.length; i++ ){
let section = sections[i];

if (section.mdTemplate) {
section.html = templateToHtml(section);
let psubs = parseSubsections( section );

let subs = section.sections = section.sections || [];
section.sections = subs.concat( psubs );
}

if( section.layout ){ section.name = section.layout.name; }

section.id = (parent.name ? (toUrl(parent.name) + '/') : '') + toUrl( section.name );
Expand Down Expand Up @@ -322,12 +346,88 @@ function compileConfig( config ){
}
}

function sortSoftwareVersions(versions, type) {
return versions.sort((a, b) => {
var aParts, bParts;
if (type === 'major') {
aParts = a.version.split('.');
bParts = b.version.split('.');
}
else {
aParts = a.split('.');
bParts = b.split('.');
}

for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {
const aNum = Number(aParts[i]) || 0;
const bNum = Number(bParts[i]) || 0;

if (aNum > bNum) return -1;
else if (aNum < bNum) return 1;
}

return 0;
});
}

function getMilestoneLink(minor_ver) {
return "https://github.com/cytoscape/cytoscape.js/issues?q=milestone%3A".concat(minor_ver).concat("+is%3Aclosed");
}

function getVersionMap(all_versions) {
const version_map = new Map();
const breakpoint = /(\d+.\d+)/;
all_versions.forEach((e) => {
v = e.split(breakpoint).filter(Boolean);
if (version_map.has(v[0])) version_map.get(v[0]).push(v[1]);
else {
version_map.set(v[0], [v[1]]);
}
});

return version_map;
}

function generate_versions(context) {
let all_versions = versions.versions;
unique_versions = [...new Set(all_versions)]

const version_map = getVersionMap(unique_versions);

const data = {
major_release: []
};

for (const major_version of version_map.entries()) {
const temp = {"version" : major_version[0]};
temp["minor_release"] = [];
const sorted = sortSoftwareVersions(major_version[1], "minor");
for (let i = 0, len = sorted.length; i < len; i++) {

// sorted[i] represent the minor version and its object contains the version and the link
const temp_minor = {};
temp_minor["minor_ver"] = major_version[0].concat(sorted[i]);
temp_minor["link"] = getMilestoneLink(temp_minor["minor_ver"]);

temp["minor_release"].push(temp_minor);
}
// console.log(temp);
data.major_release.push(temp);
};

let sortedRelease = sortSoftwareVersions(data.major_release, "major");

context["major_release"] = sortedRelease;
}

function writeDocs(){

let context = config;

compileConfig( config );

let htmlTemplate = fs.readFileSync( path.join(__dirname, './template.html'), encoding);
let template = Handlebars.compile( htmlTemplate );
let context = config;
let html = template( context );

fs.writeFileSync( path.join(__dirname, 'index.html'), html, encoding);
Expand Down
2 changes: 1 addition & 1 deletion docmaker.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
]
},

{ "name": "Introduction", "md": "intro" },
{ "name": "Introduction", "mdTemplate": "intro"},

{ "name": "Notation", "md": "notation" },

Expand Down
Loading

0 comments on commit 197f4c5

Please sign in to comment.