exclude js files from eslint

theyll all be replaced anyway
This commit is contained in:
Triston Armstrong 2024-01-07 10:32:38 -06:00
parent e57213bdf3
commit 3ee2eed96e
2 changed files with 57 additions and 65 deletions

View File

@ -16,8 +16,9 @@ module.exports = {
node: true
},
files: [
'.eslintrc.{js,cjs}'
'*.ts', '*.tsx'
],
excludeFiles: ['*.js', '*.jsx'],
parserOptions: {
sourceType: 'script'
}
@ -44,6 +45,7 @@ module.exports = {
'@typescript-eslint/space-infix-ops': 'warn',
'@typescript-eslint/space-before-function-paren': 'off',
'@typescript-eslint/explicit-function-return-type': 'warn',
'@typescript-eslint/no-extraneous-class': 'off',
'@typescript-eslint/strict-boolean-expressions': [
2,
{

View File

@ -1,12 +1,12 @@
//import matter from 'gray-matter'
import { unified } from "unified";
import markdown from "remark-parse";
import { wikiLinkPlugin } from "remark-wiki-link";
import html from "remark-html";
//import frontmatter from "remark-frontmatter";
import externalLinks from "remark-external-links";
import highlight from "remark-highlight.js";
import { Node } from "./node";
// import matter from 'gray-matter'
import { unified } from 'unified'
import markdown from 'remark-parse'
import { wikiLinkPlugin } from 'remark-wiki-link'
import html from 'remark-html'
// import frontmatter from "remark-frontmatter";
import externalLinks from 'remark-external-links'
import highlight from 'remark-highlight.js'
import { Node } from './node'
import rehypePrism from 'rehype-prism-plus'
import remarkRehype from 'remark-rehype'
import rehypeStringify from 'rehype-stringify'
@ -14,32 +14,30 @@ import obsidianImage from './obsidian-image.js'
import Utils from '../lib/utils.js'
export class Transformer {
static haveFrontMatter = (content) => {
//console.log("\t Front matter data content", content)
if (!content) return false
const indexOfFirst = content.indexOf("---");
//console.log("\t Front matter data firstIndex ", indexOfFirst)
//console.log("index first", indexOfFirst)
// console.log("\t Front matter data content", content)
if (content === (null | undefined | '')) return false
const indexOfFirst = content.indexOf('---')
// console.log("\t Front matter data firstIndex ", indexOfFirst)
// console.log("index first", indexOfFirst)
if (indexOfFirst === -1) {
return false
}
let indexOfSecond = content.indexOf("---", (indexOfFirst + 1));
return indexOfSecond !== -1;
const indexOfSecond = content.indexOf('---', (indexOfFirst + 1))
return indexOfSecond !== -1
}
static getFrontMatterData = (filecontent) => {
//if (Transformer.haveFrontMatter(filecontent)) {
// if (Transformer.haveFrontMatter(filecontent)) {
// return matter(filecontent).data
//}
// }
return {}
}
static pageResolver = (pageName) => {
const allFileNames = Utils.getAllMarkdownFiles()
const result = allFileNames.find(aFile => {
let parseFileNameFromPath = Transformer.parseFileNameFromPath(aFile);
const parseFileNameFromPath = Transformer.parseFileNameFromPath(aFile)
return Transformer.normalizeFileName(parseFileNameFromPath) === Transformer.normalizeFileName(pageName)
}
)
@ -51,12 +49,12 @@ export class Transformer {
}
// console.log("Internal Link resolved: [" + pageName + "] ==> [" + temp[0] +"]")
return (result !== undefined && result.length > 0) ? [Utils.toSlug(result)] : ["/"]
return (result !== undefined && result.length > 0) ? [Utils.toSlug(result)] : ['/']
}
static hrefTemplate = (permalink) => {
// permalink = Transformer.normalizeFileName(permalink)
permalink = permalink.replace("ç", "c").replace("ı", "i").replace("ş", "s")
permalink = permalink.replace('ç', 'c').replace('ı', 'i').replace('ş', 's')
return `/notes/${permalink}`
}
@ -68,7 +66,7 @@ export class Transformer {
.use(markdown, { gfm: true })
.use(obsidianImage)
.use(highlight)
.use(externalLinks, { target: "_blank", rel: ['noopener'] })
.use(externalLinks, { target: '_blank', rel: ['noopener'] })
// .use(frontmatter, ['yaml', 'toml'])
.use(wikiLinkPlugin, {
permalinks: null,
@ -76,84 +74,83 @@ export class Transformer {
return Transformer.pageResolver(pageName)
},
hrefTemplate: (permalink) => {
return Transformer.hrefTemplate(permalink);
return Transformer.hrefTemplate(permalink)
},
aliasDivider: "|"
aliasDivider: '|'
})
.use(remarkRehype)
.use(rehypePrism)
.use(rehypeStringify)
.process(sanitizedContent,
function(err, file) {
htmlContent.push(String(file).replace("\n", ""))
if (err) {
console.log("ERRROR:" + err)
htmlContent.push(String(file).replace('\n', ''))
if (err !== (null | undefined)) {
console.log('ERRROR:' + err)
}
}
)
htmlContent = htmlContent.join("")
htmlContent = htmlContent.split("---")
htmlContent = htmlContent.join('')
htmlContent = htmlContent.split('---')
return [htmlContent]
}
/* SANITIZE MARKDOWN FOR --- */
static preprocessThreeDashes = (content) => {
const indexOfFirst = content.indexOf("---");
const indexOfFirst = content.indexOf('---')
if (indexOfFirst === -1) {
return content
}
const indexOfSecond = content.indexOf("---", (indexOfFirst + 1));
content.slice(0, indexOfSecond);
const contentPart = content.slice(indexOfSecond);
return contentPart.split("---").join("")
const indexOfSecond = content.indexOf('---', (indexOfFirst + 1))
content.slice(0, indexOfSecond)
const contentPart = content.slice(indexOfSecond)
return contentPart.split('---').join('')
}
/* Normalize File Names */
static normalizeFileName = (filename) => {
let processedFileName = filename.replace(".md", "");
let processedFileName = filename.replace('.md', '')
processedFileName = processedFileName.replace('(', '').replace(')', '')
processedFileName = processedFileName.split(" ").join("-")
processedFileName = processedFileName.split(' ').join('-')
processedFileName = processedFileName.toLowerCase()
const conversionLetters = [
["ç", "c"], ["ş", "s"], ["ı", "i"], ["ü", "u"], ["ö", "o"], ["ğ", "g"],
["Ç", "C"], ["Ş", "S"], ["İ", "I"], ["Ü", "U"], ["Ö", "O"], ["Ğ", "G"]
['ç', 'c'], ['ş', 's'], ['ı', 'i'], ['ü', 'u'], ['ö', 'o'], ['ğ', 'g'],
['Ç', 'C'], ['Ş', 'S'], ['İ', 'I'], ['Ü', 'U'], ['Ö', 'O'], ['Ğ', 'G']
];
]
conversionLetters.forEach(letterPair => {
processedFileName = processedFileName.split(letterPair[0]).join(letterPair[1])
//processedFileName = processedFileName.replace(letterPair[0], letterPair[1])
// processedFileName = processedFileName.replace(letterPair[0], letterPair[1])
}
)
//console.log("filename", processedFileName)
// console.log("filename", processedFileName)
return processedFileName
}
/* Parse file name from path then sanitize it */
static parseFileNameFromPath = (filepath) => {
if (typeof filepath === 'string' && filepath.includes("/")) {
const parsedFileFromPath = filepath.split("/")[filepath.split("/").length - 1]
return parsedFileFromPath.replace(".md", "")
if (typeof filepath === 'string' && filepath.includes('/')) {
const parsedFileFromPath = filepath.split('/')[filepath.split('/').length - 1]
return parsedFileFromPath.replace('.md', '')
} else {
console.log("Failed: CANNOT Parse" + filepath)
console.log('Failed: CANNOT Parse' + filepath)
return null
}
}
/* Pair provided and existing Filenames*/
/* Pair provided and existing Filenames */
static getInternalLinks = (aFilePath) => {
const fileContent = Node.readFileSync(aFilePath);
const fileContent = Node.readFileSync(aFilePath)
const internalLinks = []
const sanitizedContent = Transformer.preprocessThreeDashes(fileContent)
unified()
.use(markdown, { gfm: true })
.use(wikiLinkPlugin, {
pageResolver: function(pageName) {
// let name = [Transformer.parseFileNameFromPath(pageName)];
let canonicalSlug;
if (pageName.includes('#')) {
let canonicalSlug
if (pageName.includes('#') !== (false, null, undefined)) {
// console.log(pageName)
const tempSlug = pageName.split('#')[0]
if (tempSlug.length === 0) {
@ -172,27 +169,20 @@ export class Transformer {
shortSummary: canonicalSlug
}
if (canonicalSlug != null && internalLinks.indexOf(canonicalSlug) < 0) {
internalLinks.push(backLink);
if (canonicalSlug != null && !internalLinks.includes(canonicalSlug)) {
internalLinks.push(backLink)
}
return [canonicalSlug]
}
,
},
hrefTemplate: (permalink) => {
return Transformer.hrefTemplate(permalink)
},
aliasDivider: "|"
aliasDivider: '|'
})
.use(html)
.processSync(sanitizedContent)
// console.log("Internal Links of: " + aFilePath)
// internalLinks.forEach(aLink => {
// console.log(aLink.title + " --> " + aLink.slug)
// })
// console.log("===============Internal Links")
return internalLinks;
return internalLinks
}
}