Skip to content

Commit

Permalink
chore(ethereum#6392): set basic types
Browse files Browse the repository at this point in the history
  • Loading branch information
nikkhielseath committed Jul 25, 2022
1 parent 1341083 commit 737930a
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/scripts/generate-heading-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@ const GitHubSlugger = require("github-slugger")

// TODO we should auto-run this script when new markdown files are added to the project

const toc = {}
//FIXME: Find a better name for this variable
const toc: Record<
number,
{
text: string
slug: string
}
> = {}

let curLevel = [0, 0, 0]
let curMaxLevel = 1

const walk = (dir, doc) => {
let results = []
const list = fs.readdirSync(dir)
list.forEach(function (file) {
file = dir + "/" + file
//TODO: Figure out what `doc` is and rename it to something better
const walk = (directoryPath: string, doc: string | null) => {
let results: Array<string> = []
const directoryContents: Array<string> = fs.readdirSync(directoryPath)
directoryContents.forEach(function (file) {
file = directoryPath + "/" + file
const stat = fs.statSync(file)
if (stat && stat.isDirectory()) {
// Recurse into a subdirectory
Expand All @@ -41,7 +49,7 @@ const walk = (dir, doc) => {
return results
}

const stripLinks = (line) => {
const stripLinks = (line): number => {
return line.replace(/\[([^\]]+)\]\([^)]+\)/, (match, p1) => p1)
}

Expand Down Expand Up @@ -72,7 +80,7 @@ const addHeaderID = (line, slugger, write = false) => {
curLevel[l] = 0
}
curMaxLevel = 1
const headerNumber = curLevel.join(".")
const headerNumber: string = curLevel.join(".")
let slug = null
if (!write) {
// const match = /^.+(\s*\{#([A-Za-z0-9\-_]+?)\}\s*)$/.exec(line);
Expand Down Expand Up @@ -126,7 +134,7 @@ const addHeaderIDs = (lines, write = false) => {
return results
}

const traverseHeaders = (path, doc = "", write = false) => {
const traverseHeaders = (path: string, doc = "", write = false) => {
const files = walk(path, doc)
files.forEach((file) => {
if (!file.endsWith(".md")) {
Expand Down

0 comments on commit 737930a

Please sign in to comment.