Commit 514fdb00 authored by Athanasios Katsadas's avatar Athanasios Katsadas 🔎
Browse files

calculate correctly the term url

parent 5f2d7098
Pipeline #15572 passed with stage
in 2 minutes and 5 seconds
...@@ -15,6 +15,17 @@ String.prototype.insert = function(index, string) { ...@@ -15,6 +15,17 @@ String.prototype.insert = function(index, string) {
return string + this; return string + this;
}; };
function getRelativePath(source,target) {
// calculate relative path from each file's parent dir
const sourceDir = source.substr(0, source.lastIndexOf("/"));
const targetDir = target.substr(0, target.lastIndexOf("/"));
const relative_url = path.relative(sourceDir, targetDir);
// construct the final url by appending the target's filename
// if the relative url is empty, it means that the referenced
// term is in the same dir, so add a `.`
return relative_url === '' ? '.' + target.substr(target.lastIndexOf("/")) : relative_url + target.substr(target.lastIndexOf("/"));
}
function getImportStatement(filePath) { function getImportStatement(filePath) {
var filePath = path.dirname(filePath); var filePath = path.dirname(filePath);
var absoluteTermPath = path.resolve('./src/components'); var absoluteTermPath = path.resolve('./src/components');
...@@ -70,8 +81,11 @@ async function parser(err, files) { ...@@ -70,8 +81,11 @@ async function parser(err, files) {
// Get the popup text for the term // Get the popup text for the term
let hoverText = await getHoverText(referencePath); let hoverText = await getHoverText(referencePath);
const current_file_path = path.resolve(process.cwd(), filepath);
const term_path = path.resolve(process.cwd(), TERMS_DIR, reference);
const new_final_url = getRelativePath(current_file_path, term_path);
var new_text = ('<Term popup="' + hoverText + '" reference="' + var new_text = ('<Term popup="' + hoverText + '" reference="' +
reference + '">' + text + '</Term>'); new_final_url + '">' + text + '</Term>');
content = content.replace(regex_match, new_text); content = content.replace(regex_match, new_text);
} }
// Find the index of the 2nd occurrence of '---' // Find the index of the 2nd occurrence of '---'
......
"use strict"; "use strict";
const TERMS_DIR = './terms/';
const React = require('react'); const React = require('react');
const { Link } = require('react-router-dom'); const { Link } = require('react-router-dom');
const { Tooltip } = require('@material-ui/core') const { Tooltip } = require('@material-ui/core')
require('./style.css'); require('./style.css');
function get_pathname(reference) { function get_pathname(reference) {
return { pathname: TERMS_DIR + reference }; return { pathname: reference };
} }
const Term = ({children, reference, popup}) => { const Term = ({children, reference, popup}) => {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment