diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index a64ad4b..7f19427 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -8,6 +8,10 @@ on: # Allows you to run this workflow manually from the Actions tab workflow_dispatch: +env: + SYSTEM_NAME_COMMAND: systemname + SYSTEM_NAME: griffith + # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages permissions: contents: read @@ -30,14 +34,18 @@ jobs: container: arcatdmz/texlive steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Build PDF file - run: latexmk -pdf && latexmk -c && mkdir -p docs && cp *.pdf ./docs/ + run: latexmk -pdf + - name: Run scripts + run: node scripts/abstract.js > abstract.log + - name: Organize files to upload + run: mkdir -p docs && cp *.pdf *.log ./docs/ - name: Upload artifact - uses: actions/upload-pages-artifact@v1 + uses: actions/upload-pages-artifact@v3 with: # Upload "docs" directory path: "docs" - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v1 + uses: actions/deploy-pages@v4 diff --git a/main.tex b/main.tex index db7c0d6..317ff58 100644 --- a/main.tex +++ b/main.tex @@ -198,6 +198,8 @@ %% of authors' names for this purpose. \renewcommand{\shortauthors}{Trovato et al.} +\newcommand{\systemname}{Griffith} + %% %% The abstract is a short summary of the work to be presented in the %% article. @@ -208,6 +210,7 @@ article presents and explains many of the common variations, as well as many of the formatting elements an author may use in the preparation of the documentation of their work. + If I were to name this system, it should be \systemname. \end{abstract} %% diff --git a/scripts/abstract.js b/scripts/abstract.js new file mode 100644 index 0000000..38a8e56 --- /dev/null +++ b/scripts/abstract.js @@ -0,0 +1,80 @@ +const fs = require("fs"); + +const sysinExp = `\\${process.env.SYSTEM_NAME_COMMAND || "systemname"}`; +const sysout = process.env.SYSTEM_NAME || "Geollery"; + +function WordCount(str) { + return str.split(/\s+/).length; +} + +function Analyze(a) { + var res = a.trim(); + // begin re_abstract + const startWord = "\\begin{abstract}"; + let start = res.indexOf(startWord), + end = res.indexOf("\\end{abstract"); + if (start >= 0 && end >= start) { + res = res.substring(start + startWord.length, end).trim(); + } + + // ieee \re_abstract + re_abs = /\\re_abstract{(.+)}/gm; + match = re_abs.exec(res); + if (match && match[1]) { + res = match[1]; + } + + // citations + res = res.replace(/\\cite\{[\w\d,:]+\}/g, ""); + res = res.replace(/\\ref\{[\w\d,:]+\}/g, "X"); + res = res.replace(/\\begin\{[\w\d,:]+\}\[.+\]/g, ""); + res = res.replace(/\\end\{[\w\d,:]+\}/g, ""); + res = res.replace(/\\label\{[\w\d,:]+\}/g, ""); + res = res.replace(/\\centering/g, ""); + res = res.replace(/\\caption/g, ""); + res = res.replace( + /\\includegraphics[\[\w\d\,\.\:\=\/\\]+\]\{[\w\d,\.\:\/\\\_]+\}/g, + "" + ); + + // latex symbols + res = res.replace(/\\degree/g, "°"); + res = res.replace(/\\times/g, "×"); + res = res.replace(/\\etal/g, "et al."); + res = res.replace(/``/g, '"'); + res = res.replace(/""/g, '"'); + res = res.replace(/\'\'/g, '"'); + res = res.replace(/\\&/g, "&"); + res = res.replace(/ \./g, "."); + let sysin = new RegExp("\\" + sysinExp, "g"); + res = res.replace(sysin, sysout); + + // comments + res = res.replace(/([^\\]|^)%.+/gm, ""); // Fixed for Firefox + + // emph and italics + res = res.replace(/\{\\\w+/gm, "").replace(/\\\/\}/g, ""); + + // textit, $, and ~ + res = res + .replace(/\\\w+{/gm, "") + .replace(/[\}\$]/g, "") + .replace(/\~/g, " "); + res = res.replace(/\\sim/g, "~"); + + // double white spaces + res = res.replace(/\n/g, " "); + res = res.replace(/\s\s+/g, " "); + res = res.replace(/([\.,])(\s)([\.,])/g, "$1$3"); + + // \% percentage + res = res.replace(/\\\%/g, "%"); + res = res.trim(); + + return { wc: WordCount(res), res }; +} + +const content = fs.readFileSync("main.tex", { encoding: "utf8" }); +const { wc, res } = Analyze(content); +console.log("Word count: %d", wc); +console.log(res);