linkedin-studio/hooks/scripts/linkedin-content-filter.mjs

47 lines
2.1 KiB
JavaScript

#!/usr/bin/env node
// Shared module: determines if a file path is LinkedIn content
// Import: import { isLinkedInContent } from './linkedin-content-filter.mjs';
// Returns true for content, false for non-content
import { basename, extname } from 'node:path';
export function isLinkedInContent(filePath) {
if (!filePath) return false;
const base = basename(filePath);
const ext = extname(base).slice(1); // remove leading dot
// NEGATIVE: code/config extensions
if (['sh', 'py', 'js', 'mjs', 'ts', 'jsx', 'tsx', 'json', 'yaml', 'yml', 'toml', 'css', 'html'].includes(ext)) {
return false;
}
// NEGATIVE: template files
if (base.includes('.template')) return false;
// NEGATIVE: known non-content filenames
const nonContent = ['.local.md', 'CLAUDE.md', 'README.md', 'CHANGELOG.md', 'REMEMBER.md', 'BACKLOG.md', 'DEVELOPMENT-LOG.md'];
if (nonContent.some(n => base.endsWith(n) || base === n)) return false;
const normalized = filePath.replace(/\\/g, '/');
// POSITIVE (external): relocated drafts under the per-user data root are the
// only external data class the Write/Edit quality gate guards (voice-samples /
// analytics / profile are not editor-gated content). Must come BEFORE the
// infraDirs negative below, which would otherwise reject any /.claude/ path.
if (normalized.startsWith('.claude/linkedin-studio/drafts/') || normalized.includes('/.claude/linkedin-studio/drafts/')) return true;
// NEGATIVE: infrastructure paths
const infraDirs = ['hooks', 'scripts', 'config', 'commands', 'agents', 'skills', 'references', 'docs', '.claude', '.claude-plugin', 'node_modules'];
for (const dir of infraDirs) {
if (normalized.startsWith(dir + '/') || normalized.includes('/' + dir + '/')) return false;
}
// POSITIVE: explicit LinkedIn content paths only
if (normalized.startsWith('assets/drafts/') || normalized.includes('/assets/drafts/')) return true;
if (normalized.includes('/linkedin-posts/')) return true;
if (normalized.includes('/linkedin-studio/assets/')) return true;
// DEFAULT: everything else is NOT LinkedIn content
return false;
}