pagefind integration and search bar
This commit is contained in:
		
							parent
							
								
									a787497feb
								
							
						
					
					
						commit
						cd1226e333
					
				
					 19 changed files with 565 additions and 240 deletions
				
			
		
							
								
								
									
										28
									
								
								pagefind.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								pagefind.ts
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,28 @@
 | 
			
		|||
import type { AstroIntegration } from "astro";
 | 
			
		||||
import { fileURLToPath } from "node:url";
 | 
			
		||||
import { spawn } from "node:child_process";
 | 
			
		||||
import { dirname, relative } from "node:path";
 | 
			
		||||
 | 
			
		||||
export default function pagefind(): AstroIntegration {
 | 
			
		||||
  return {
 | 
			
		||||
    name: "pagefind",
 | 
			
		||||
    hooks: {
 | 
			
		||||
      "astro:build:done": ({ dir }) => {
 | 
			
		||||
        const targetDir = fileURLToPath(dir);
 | 
			
		||||
        const cwd = dirname(fileURLToPath(import.meta.url));
 | 
			
		||||
        const relativeDir = relative(cwd, targetDir);
 | 
			
		||||
        return new Promise<void>(resolve => {
 | 
			
		||||
          spawn(
 | 
			
		||||
            "yarn dlx",
 | 
			
		||||
            ["-q", "pagefind", "--site", relativeDir],
 | 
			
		||||
            {
 | 
			
		||||
              stdio: "inherit",
 | 
			
		||||
              shell: true,
 | 
			
		||||
              cwd,
 | 
			
		||||
            }
 | 
			
		||||
          ).on("close", () => resolve());
 | 
			
		||||
        });
 | 
			
		||||
      },
 | 
			
		||||
    },
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue