Skip to content
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: introduce Opportunity creation for Broken Backlinks #475

Merged
merged 19 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,50 @@ export default new AuditBuilder()
.build();

```

### How to add Opportunities and Suggestions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

```js
import { syncSuggestions } from '../utils/data-access.js';

export async function auditRunner(url, context) {

// your audit logic goes here...

return {
auditResult: results,
fullAuditRef: baseURL,
};
}

async function convertToOpportunity(auditUrl, auditData, context) {
const { dataAccess } = context;

const opportunity = Opportunity.create(opportunityData);

// this logic changes based on the audit type
const buildKey = (auditData) => `${auditData.property}|${auditData.anotherProperty}`;

await syncSuggestions({
opportunity,
newData: auditData,
buildKey,
mapNewSuggestion: (issue) => ({
opportunityId: opportunity.getId(),
type: 'SUGGESTION_TYPE',
rank: issue.rankMetric,
// data changes based on the audit type
data: {
property: issue.property,
anotherProperty: issue.anotherProperty
}
}),
log
});
}

export default new AuditBuilder()
.withRunner(auditRunner)
.withPostProcessors([ convertToOpportunity ])
.build();

```
Loading