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

View File

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