Digested-Tile 2024-09-13

Authors:: Unknown License:: Unspecified Digest Root:: b32afd37319f

MarkdownTile

splitIntoTiles.js

function splitIntoTiles(content) {
    // Extract frontmatter if present
    const frontmatterMatch = content.match(/^\s*---\n[\s\S]*?\n---\s*$/m);
    const frontmatter = frontmatterMatch ? frontmatterMatch[0] : '';
    // Remove frontmatter from the main content
    const contentWithoutFrontmatter = content.replace(/^\s*---\n[\s\S]*?\n---\s*\n/m, '');
 
    // Regex to match both Markdown (### Header) and HTML (<h3>Header</h3>) headers
    const headerRegex = /^(?:#{1,3}\s+.*|(?:<h[1-3]>.*?<\/h[1-3]>))$/gm;
    const tiles = [];
    let lastIndex = 0;
    let match;
 
    // Check if there's content before the first header
    const firstHeaderMatch = contentWithoutFrontmatter.match(headerRegex);
    if (firstHeaderMatch && firstHeaderMatch.index > 0) {
        // Add content before first header as a tile
        tiles.push(contentWithoutFrontmatter.slice(0, firstHeaderMatch.index).trim());
        lastIndex = firstHeaderMatch.index;
    }
 
    // Iterate through all header matches
    while ((match = headerRegex.exec(contentWithoutFrontmatter)) !== null) {
        if (lastIndex !== match.index) {
            // Add content between headers as a tile
            tiles.push(contentWithoutFrontmatter.slice(lastIndex, match.index).trim());
        }
        lastIndex = match.index;
    }
 
    // Add any remaining content after the last header
    if (lastIndex < contentWithoutFrontmatter.length) {
        tiles.push(contentWithoutFrontmatter.slice(lastIndex).trim());
    }
 
    // Count frontmatter properties
    const frontmatterProperties = frontmatter
        .split('\n')
        .filter(line => line.includes(':'))
        .length;
 
    // Log information about the splitting process
    console.log(`Splitting content into ${tiles.length} tiles, and preserving ${frontmatterProperties} frontmatter properties`);
 
    // Return an object containing the frontmatter and the array of tiles
    return { frontmatter, tiles };
}
 
// Export the function for use in other modules
module.exports = splitIntoTiles;
DeformattedTile

splitIntoTiles.js

function splitIntoTiles(content) {
    // Extract frontmatter if present
    const frontmatterMatch = content.match(/^\s*---\n[\s\S]*?\n---\s*$/m);
    const frontmatter = frontmatterMatch ? frontmatterMatch[0] : '';
    // Remove frontmatter from the main content
    const contentWithoutFrontmatter = content.replace(/^\s*---\n[\s\S]*?\n---\s*\n/m, '');
    // Regex to match both Markdown (### Header) and HTML (<h3>Header</h3>) headers
    const headerRegex = /^(?:#{1,3}\s+.*|(?:<h[1-3]>.*?<\/h[1-3]>))$/gm;
    const tiles = [];
    let lastIndex = 0;
    let match;
    // Check if there's content before the first header
    const firstHeaderMatch = contentWithoutFrontmatter.match(headerRegex);
    if (firstHeaderMatch && firstHeaderMatch.index > 0) {
        // Add content before first header as a tile
        tiles.push(contentWithoutFrontmatter.slice(0, firstHeaderMatch.index).trim());
        lastIndex = firstHeaderMatch.index;
    }
    // Iterate through all header matches
    while ((match = headerRegex.exec(contentWithoutFrontmatter)) !== null) {
        if (lastIndex !== match.index) {
            // Add content between headers as a tile
            tiles.push(contentWithoutFrontmatter.slice(lastIndex, match.index).trim());
        }
        lastIndex = match.index;
    }
    // Add any remaining content after the last header
    if (lastIndex < contentWithoutFrontmatter.length) {
        tiles.push(contentWithoutFrontmatter.slice(lastIndex).trim());
    }
    // Count frontmatter properties
    const frontmatterProperties = frontmatter
        .split('\n')
        .filter(line => line.includes(':'))
        .length;
    // Log information about the splitting process
    console.log(`Splitting content into ${tiles.length} tiles, and preserving ${frontmatterProperties} frontmatter properties`);
    // Return an object containing the frontmatter and the array of tiles
    return { frontmatter, tiles };
}
// Export the function for use in other modules
module.exports = splitIntoTiles;
EOT