mirror of https://github.com/onweru/compose.git

weru
13.37.2020 02659eaa018774735c428123e9746f5cb8d8c349
update
2 files modified
41 ■■■■■ changed files
assets/js/functions.js 36 ●●●●● patch | view | raw | blame | history
assets/js/search.js 5 ●●●●● patch | view | raw | blame | history
assets/js/functions.js
@@ -107,11 +107,11 @@
  }
}
function wrapText(text, context) {
  function wrap(context, wrapper = 'mark') {
function wrapText(text, context, wrapper = 'mark') {
  let open = `<${wrapper}>`;
  let close = `</${wrapper}>`;
  function wrap(context) {
    let c = context.innerHTML;
    let open = `<${wrapper}>`;
    let close = `</${wrapper}>`;
    let index = c.indexOf(text);
    if (index >= 0) {
      let stop = index + text.length;
@@ -120,20 +120,11 @@
      let after = c.substring(stop);
      c = `${before}${open}${s}${close}${after}`;
      context.innerHTML = c;
      // add class attribute later if need be
      const attributes = ["href", "id", "title"];
      attributes.forEach(function(attr){
        if(context.hasAttribute(attr)) {
          let attrValue = context.getAttribute(attr);
          context.setAttribute(attr, attrValue.replaceAll(`${open}`,"").replaceAll(`${close}`,""));
        }
      });
    }
  }
  const contents = ["h1", "h2", "h3", "h4", "h5", "h6", "p", "code", "td", "pre"];
  const children = ["span", "em", "strong", "b", "a"];
  contents.forEach(function(c){
    const cs = elems(c, context);
    if(cs.length) {
@@ -146,14 +137,17 @@
        } else {
          wrap(cx);
        }
        // check if
        // if has children
           // check if childen is in children array above
           // filter out children if listed in cs array above
           // check if children contain attributes
          // process before replacing
        // else replace and move on
        // sanitize urls and ids
      });
    }
  });
  const hyperLinks = elems('a');
  if(hyperLinks) {
    hyperLinks.forEach(function(link){
      const href = link.href.replaceAll(encodeURI(open), "").replaceAll(encodeURI(close), "");
      console.log(open, close);
      link.href = href;
    });
  }
}
assets/js/search.js
@@ -13,8 +13,9 @@
  ignoreLocation: true,
  findAllMatches: true,
  includeScore: true,
  shouldSort: true,
  keys: searchKeys,
  threshold: 0.1
  threshold: 0.0
};
const index = new Fuse(idx, searchOptions);
@@ -28,7 +29,7 @@
    resultsTitle.className = 'search_title';
    resultsTitle.innerText = 'Quick Links';
    resultsFragment.appendChild(resultsTitle);
    results.slice(0,6).forEach(function(result){
    results.slice(0,4).forEach(function(result){
      let item = createEl('a');
      item.href = `${result.link}?query=${query}`;
      item.className = 'search_result';