MCPcopy Index your code
hub / github.com/github/docs / removeFromChildren

Function removeFromChildren

script/move-content.js:302–348  ·  view source on GitHub ↗
(oldPath, opts)

Source from the content-addressed store, hash-verified

300}
301
302function removeFromChildren(oldPath, opts) {
303 const { verbose } = opts
304
305 const parentFilePath = path.join(path.dirname(oldPath), 'index.md')
306 const fileContent = fs.readFileSync(parentFilePath, 'utf-8')
307 const { content, data } = readFrontmatter(fileContent)
308 const oldName = getBasename(oldPath)
309
310 let childrenPosition = -1
311 if (CHILDREN_KEY in data) {
312 data[CHILDREN_KEY] = data[CHILDREN_KEY].filter((entry, i) => {
313 if (entry === oldName || entry === `/${oldName}`) {
314 childrenPosition = i
315 return false
316 }
317 return true
318 })
319 if (data[CHILDREN_KEY].length === 0) {
320 delete data[CHILDREN_KEY]
321 }
322 }
323
324 const childGroupPositions = []
325
326 ;(data[CHILDGROUPS_KEY] || []).forEach((group, i) => {
327 if (group.children) {
328 group.children = group.children.filter((entry, j) => {
329 if (entry === oldName || entry === `/${oldName}`) {
330 childGroupPositions.push([i, j])
331 return false
332 }
333 return true
334 })
335 }
336 })
337
338 fs.writeFileSync(
339 parentFilePath,
340 readFrontmatter.stringify(content, data, { lineWidth: 10000 }),
341 'utf-8'
342 )
343 if (verbose) {
344 console.log(`Removed 'children' (${oldName}) key in ${parentFilePath}`)
345 }
346
347 return { childrenPosition, childGroupPositions }
348}
349
350function addToChildren(newPath, positions, opts) {
351 const { verbose } = opts

Callers 3

mainFunction · 0.85
editFilesFunction · 0.85
undoFilesFunction · 0.85

Calls 2

readFrontmatterFunction · 0.85
getBasenameFunction · 0.85

Tested by

no test coverage detected