Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add docs attribution statement, purge the readme content #1111

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dsmmcken
Copy link
Contributor

@dsmmcken dsmmcken commented Feb 5, 2025

No description provided.

Copy link

github-actions bot commented Feb 5, 2025

ui docs preview (Available for 14 days)

Copy link
Member

@mofojed mofojed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably remove the no longer used images as well.

my_input = ui_input()
```

![Text field.](_assets/text_field.png)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many of these images are no longer referenced and can be removed as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man, AI is pretty handy. Would have taken some effort to do manually, can instead just ask AI write me a on-off script to do it, that way I didn't have to check if any of the docs proper used any of the images either.

/**
 * This node script reads all the files in the ./_assets directory and then reads all the .md files
 * in the current directory recusively and then checks if the file is used in any of the .md files
 *
 * If the file is not used in any of the .md files, it will be deleted.
 *
 * Compare only the file name and extension, not the path.
 */

const path = require('path');
const fs = require('fs');

function getAllMdFiles(dir, fileList = []) {
  const files = fs.readdirSync(dir);
  files.forEach(file => {
    const filePath = path.join(dir, file);
    const stat = fs.statSync(filePath);
    if (stat.isDirectory()) {
      getAllMdFiles(filePath, fileList);
    } else if (filePath.endsWith('.md')) {
      fileList.push(filePath);
    }
  });
  return fileList;
}

function isAssetUsedInMd(assetName, mdFiles) {
  return mdFiles.some(mdFile => {
    const content = fs.readFileSync(mdFile, 'utf8');
    const isUsed = content.includes(assetName);
    if (isUsed) {
      console.log(`Asset ${assetName} is used in ${mdFile}`);
    }
    return isUsed;
  });
}

(function purgeUnusedAssets() {
  const assetDir = path.join(__dirname, '_assets');
  if (!fs.existsSync(assetDir)) {
    console.log(`No _assets directory found at ${assetDir}`);
    return;
  }

  const mdFiles = getAllMdFiles(__dirname, []);
  const assets = fs.readdirSync(assetDir);

  assets.forEach(asset => {
    const assetName = asset; // match just the filename
    console.log(`Checking asset: ${assetName}`);
    if (!isAssetUsedInMd(assetName, mdFiles)) {
      const assetPath = path.join(assetDir, assetName);
      console.log(`Removing unused asset: ${assetPath}`);
      fs.unlinkSync(assetPath);
    }
  });

  console.log('Purge complete.');
})();

@dsmmcken dsmmcken requested a review from mofojed February 6, 2025 16:00
Copy link

github-actions bot commented Feb 6, 2025

ui docs preview (Available for 14 days)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants