Example #1
0
async function main() {
  fontName = process.argv[2];
  ligFontName = fontName.split('-').join('Lig-');

  const srcFileName = `./original/${fontName}.ttx`;
  const dstFileName = `./build/${ligFontName}.ttx`;
  console.log(`Reading original font file ${srcFileName}`);
  const xml = await fs.readFileAsync(srcFileName, 'utf-8');
  const dom = new DOMParser().parseFromString(xml);

  try {
    await processPatch('names', patchNames, dom);
    await processPatch('glyphs', patchGlyphs, dom);
    await processPatch('gpos', patchGpos, dom);
    await processPatch('gsub', patchGsub, dom);
    await processPatch('hmtx', patchHmtx, dom);
    //await processPatch('lookup', patchLookup, dom);
    await processPatch('charstrings', patchCharStrings, dom);
  } catch (err) {
    console.log(err);
  }

  console.log(`Writing ligature font file ${dstFileName}`);
  await fs.writeFileAsync(dstFileName, format(serialize(dom)));
  console.log('Done');
}
Example #2
0
function prettyPrintXml(xml, indent) {
  // This works well, because we format the xml before applying the replacements
  const prettyXml = xmlFormat(xml, {indentation: '  '})
    // Matches `<{prefix}:{name} .*?>`
    .replace(/<(\/)?((?:[\w]+)(?::))?([\w]+)(.*?)>/g, chalk`<{green $1$2{bold $3}}$4>`)
    // Matches ` {attribute}="{value}"
    .replace(/ ([\w:]+)="(.+?)"/g, chalk` {white $1}={cyan "$2"}`);
  if (indent) {
    return prettyXml.replace(/(^|\n)/g, `$1${' '.repeat(indent)}`);
  }
  return prettyXml;
}
Example #3
0
  return new Promise(async (resolve, reject) => {
    if (env['process.env.TEST'] === 'cypress') {
      resolve('Sitemap building skipped in cypress')
      return
    }
    console.log('Building sitemap...')
    try {
      let diskPages = glob.sync(SOURCE)
      const content = fs.readFileSync(
        path.join(process.cwd(), 'server/server.js'),
        {
          encoding: 'utf8'
        }
      )

      const regex = /'\/(.*?)'/g

      const routes = content.match(regex)

      let xml = ''
      xml += '<?xml version="1.0" encoding="UTF-8"?>'
      xml += `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
      xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
         http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">`

      diskPages.forEach((page) => {
        let stats = fs.statSync(page)
        let modDate = new Date(stats.mtime)
        let lastMod = `${modDate.getFullYear()}-${(
          '0' +
          (modDate.getMonth() + 1)
        ).slice(-2)}-${('0' + modDate.getDate()).slice(-2)}`

        page = page.replace(path.join(process.cwd(), 'pages'), '')
        page = page.replace(/.js$/, '')
        page = page.replace('/index', '')

        let matched = undefined
        routes.forEach((route, index) => {
          if (route.indexOf(page) > 0) {
            matched = routes[index - 1]
          }
        })
        if (matched) {
          page = `${SITE_ROOT}${matched.replace(/'/g, '') || page}`

          if (page.match(/.*\/index$/)) {
            page = page.replace(/(.*)index$/, '$1')
          }

          xml += '<url>'
          xml += `<loc>${page}</loc>`
          xml += `<lastmod>${lastMod}</lastmod>`
          xml += '<changefreq>always</changefreq>'
          xml += '<priority>1.0</priority>'
          xml += '</url>'
        }
      })

      fs.writeFileSync(
        DESTINATION,
        format(xml, {indentation: '  ', stripComments: true})
      )

      resolve(
        `Wrote sitemap for ${diskPages.length +
          listings.data.listings.length} pages to ${DESTINATION}`
      )
    } catch (e) {
      reject(e)
    }
  })