repo_description: Coding articles to level up your development skills
repo_topics: astro awesome-list css education es6-javascript git html javascript learn-to-code learning-resources nodejs programming snippets
code: import fs from 'fs-extra/esm';
  import Collection from '#src/models/collection.js';
  import Snippet from '#src/models/snippet.js';
  import SearchResultSerializer from '#src/serializers/searchResultSerializer.js';
  
  export default class SearchIndex {
    static generate() {
      const snippets = Snippet.scope('published', 'listed', 'byId');
      const collections = Collection.scope('listed', 'byId');
  
      const searchIndex = {
        searchIndex: SearchResultSerializer.serializeArray(
          snippets.concat(collections)
        ),
      };
  
      // Write to file
      fs.writeJson(
        'public/search-data.json',
        searchIndex,
        { spaces: 0 },
        () => {}
      );
    }
  }
  