-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add meta tags endpoint to html to pdf #789
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush. | ||
{ | ||
"pnpmShrinkwrapHash": "ef99d2be9bb5fde2af843e6f081457fe57fa679f", | ||
"pnpmShrinkwrapHash": "0f26d344f9b8b25f5850336a9f316858200a1459", | ||
"preferredVersionsHash": "a48003cf229dd47d077bcf6301ac15a6f90e1c34" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
services/html-to-pdf/src/module/meta-tags/meta-tags.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { | ||
Controller, Get, Param, Query, VERSION_NEUTRAL, | ||
} from '@nestjs/common'; | ||
import { MetaTagsService } from './meta-tags.service'; | ||
|
||
@Controller({ path: 'meta-tags', version: ['1', VERSION_NEUTRAL] }) | ||
export class MetaTagsController { | ||
constructor(private readonly metaTagsService: MetaTagsService) {} | ||
|
||
@Get() | ||
async getMetaTags( | ||
@Query('url') url: string, | ||
): Promise<{ [key: string]: string }> { | ||
return this.metaTagsService.getMetaTags(url); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
services/html-to-pdf/src/module/meta-tags/meta-tags.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { MetaTagsController } from './meta-tags.controller'; | ||
import { MetaTagsService } from './meta-tags.service'; | ||
|
||
@Module({ | ||
controllers: [MetaTagsController], | ||
providers: [MetaTagsService], | ||
}) | ||
export class MetaTagsModule {} |
36 changes: 36 additions & 0 deletions
36
services/html-to-pdf/src/module/meta-tags/meta-tags.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import axios from 'axios'; | ||
import * as cheerio from 'cheerio'; | ||
|
||
@Injectable() | ||
export class MetaTagsService { | ||
async getMetaTags(url: string): Promise<{ [key: string]: string }> { | ||
try { | ||
const response = await axios.get(url); | ||
const metaTags = this.extractMetaTags(response.data); | ||
return metaTags; | ||
} catch (err) { | ||
// Handle errors (e.g., network issues, invalid URLs) | ||
const error = err as Error; | ||
console.error('Error fetching or parsing the page:', error.message); | ||
throw new Error('Unable to fetch or parse the page'); | ||
} | ||
} | ||
|
||
private extractMetaTags(html: string): { [key: string]: string } { | ||
const $ = cheerio.load(html); | ||
const metaTags: { [key: string]: string } = {}; | ||
|
||
$('meta').each((_, element) => { | ||
const tag = $(element); | ||
const name = tag.attr('name') || tag.attr('property'); | ||
const content = tag.attr('content'); | ||
|
||
if (name && content) { | ||
metaTags[name] = content; | ||
} | ||
}); | ||
|
||
return metaTags; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Server-side request forgery Critical