Skip to content
Snippets Groups Projects
utils.ts 759 B
Newer Older
  • Learn to ignore specific revisions
  • import { ConfigurationService } from '../configuration/configuration.service';
    import { Page } from '../pages/schemas/page.schema';
    import { Post } from '../posts/schemas/post.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]
          }`;
        }
        const regex = /(https?:\/\/ghost):(\d*)?/g;
        itemData.html = itemData.html.replace(regex, `https://${configService.config.host}/blog`);
      }
      return itemData;
    }