Skip to content
Snippets Groups Projects
utils.ts 1.91 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { AnalysisAnalyzer, IndicesIndexSettings } from '@elastic/elasticsearch/lib/api/types';
    
    import { ConfigurationService } from '../configuration/configuration.service';
    import { Page } from '../pages/schemas/page.schema';
    import { Post } from '../posts/schemas/post.schema';
    
    import { UserRole } from '../users/enum/user-role.enum';
    import { User } from '../users/schemas/user.schema';
    
    
    export function rewriteGhostImgUrl(configService: ConfigurationService, itemData: Page | Post): Page | Post {
      // Handle image display. Rewrite image URL to fit ghost infra issue.
      if (!configService.isLocalConf()) {
        if (itemData.feature_image) {
          itemData.feature_image = `https://${configService.config.host}/blog/content${
            itemData.feature_image.split('/content')[1]
          }`;
        }
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
        const regex = /(https?:\/\/ghost):(\d*)?/g; //NOSONAR
    
        itemData.html = itemData.html.replace(regex, `https://${configService.config.host}/blog`);
      }
      return itemData;
    }
    
    
    export function hasAdminRole(user: User): boolean {
      return user.role === UserRole.admin;
    }
    
    const analyzer: Record<string, AnalysisAnalyzer> = {
      homemade_french: {
        type: 'custom',
        tokenizer: 'standard',
        filter: ['lowercase', 'asciifolding', 'french_elision', 'french_stop', 'french_stemmer'],
      },
      homemade_french_stopless: {
        type: 'custom',
        tokenizer: 'standard',
        filter: ['lowercase', 'asciifolding', 'french_elision', 'french_stemmer'],
      },
    };
    
    export const es_settings_homemade_french: IndicesIndexSettings = {
    
    Etienne LOUPIAS's avatar
    Etienne LOUPIAS committed
      analysis: {
        filter: {
          french_elision: {
            type: 'elision',
            articles_case: true,
            articles: ['l', 'm', 't', 'qu', 'n', 's', 'j', 'd', 'c', 'jusqu', 'quoiqu', 'lorsqu', 'puisqu'],
          },
          french_stop: {
            type: 'stop',
            stopwords: '_french_',
          },
          french_stemmer: {
            type: 'stemmer',
            language: 'minimal_french',
          },
        },
    
        analyzer: analyzer,