Skip to content

Commit

Permalink
Add blacklist and other minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thebeard committed Nov 17, 2024
1 parent 26c11b2 commit 0fb3ae9
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 22 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ _Example template_

## How to use this Github Repository to create your own Hyperlink Aggregator site

### Select your deployment method
### Select your hosting and deployment method

#### Github Pages

Expand Down Expand Up @@ -71,9 +71,24 @@ When setting up your own build and continuous integration pipelines, please note
1. Go to **Secrets and Variables** >> **Actions**
1. To the repository secrets add the `SUMMARISEAPI` secret
1. Also add the `SUMMARISEAPIKEY` you copied at step (3)
1. Go to **Actions** >> **General** and enable Github Actions
1. Go to **Pages** and for the **Build and deployment** >> **Source** setting, select **Github Actions**
1. Ensure necessary Pull Request and Commit permissions are set up to allow for post approvals by the administrator and/or moderators
1. Change the title at the top of this markdown file (`# Post Reader`)
1. Change the two intro paragraphs at the top of this markdown file, to reflect the topic and purpose of your own website.
1. In the file located at `src/app/app.config.ts` change the site title on **line 24**
1. Remove the example posts in the `src/content` folder
1. See **Base Path Management** below
1. Submit and commit your first post

### Base Path Management

Due to this repository defaulting to Github Pages, there is a deployment step in the NPM tasks in the [package.json]('./package.json) file to include a base path in the build step. Depending on your hosting selection you will have to make one of the following changes

#### Github Pages (without custom domain)

Go to the [package.json](./package.json) file, line 13, and replace `/post-reader/` with the base path associated with your Github Pages page

#### Github Pages (with custom domain) and others

Depending on your hosting/website configuration, go to the [package.json](./package.json) file and update line 13 as required. Likely you have to remove the `--base-href` argument
38 changes: 30 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"fs": "^0.0.1-security",
"fs-extra": "^11.2.0",
"gh-pages": "^6.2.0",
"jsdom": "^24.1.0",
"jsdom": "^24.1.3",
"lucide-angular": "^0.411.0",
"parse-srcset": "^1.0.2",
"rxjs": "~7.8.0",
Expand Down
21 changes: 18 additions & 3 deletions src/app/components/ai.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { booleanAttribute, ChangeDetectionStrategy, Component, HostBinding, Input } from '@angular/core';
import { LucideAngularModule } from 'lucide-angular';

@Component({
selector: 'app-ai',
template: `<div><ng-content></ng-content></div>
<mark>Article summary generated by AI <lucide-icon name="wand" [size]="15" [strokeWidth]="2"></lucide-icon></mark>`,
<mark>{{ content }} <lucide-icon name="wand" [size]="15" [strokeWidth]="2"></lucide-icon></mark>`,
styles: [
`
:host {
Expand All @@ -16,6 +16,13 @@ import { LucideAngularModule } from 'lucide-angular';
color: var(--green);
border-radius: 8px;
padding: 2px 8px;
&.failed {
border: 1px solid var(--red);
color: var(--red);
mark {
color: var(--red);
}
}
}
div {
Expand Down Expand Up @@ -46,4 +53,12 @@ import { LucideAngularModule } from 'lucide-angular';
imports: [LucideAngularModule],
standalone: true
})
export class AiComponent {}
export class AiComponent {
@HostBinding('class.failed')
@Input({ transform: booleanAttribute })
failed = false;

get content(): string {
return this.failed ? 'No article summary generated' : 'Article summary generated by AI';
}
}
19 changes: 12 additions & 7 deletions src/app/components/post/post.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ <h3>{{ post.title }}</h3>
<div class="meta">
@if(post.link) {
<a [href]="post.link" target="_blank">{{ post.link }}</a>
}

@if(post.tags.length) {
} @if(post.tags.length) {
<div class="tags">
<span>Tags:&nbsp;</span> @for(tag of post.tags; track tag; let i = $index) { @if(i) {, }
<span class="tag" (click)="tagSelected.emit(tag)">#{{ tag }}</span>
Expand All @@ -23,17 +21,24 @@ <h3>{{ post.title }}</h3>
<ng-container [ngSwitch]="content">
@if(markdown) {
<article *ngSwitchCase="'human'" [innerHTML]="markdown"></article>
<summary *ngSwitchCase="'machine'">{{ summary }}</summary>
<ng-container *ngSwitchCase="'machine'">
@if(summary) {
<summary>{{ summary }}</summary>
} @else {
<article [innerHTML]="markdown"></article>
<app-ai failed="true" />
}
</ng-container>
<ng-container *ngSwitchCase="'both'">
<article [innerHTML]="markdown"></article>
<app-ai>{{ summary }}</app-ai>
<app-ai [failed]="!summary">{{ summary }}</app-ai>
</ng-container>

} @else {
<summary *ngSwitchCase="'machine'">{{ summary }}</summary>
<ng-container *ngSwitchDefault>
<article [innerHTML]="summary"></article>
<app-ai></app-ai>
<app-ai />
</ng-container>
}
</ng-container>
</ng-container>
3 changes: 3 additions & 0 deletions src/bin/models/content-preparation-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type ContentPreparationConfig = {
blacklistScraping: string[];
};
5 changes: 5 additions & 0 deletions src/bin/prepare-content-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ContentPreparationConfig } from './models/content-preparation-config';

export const PrepareContentConfig: ContentPreparationConfig = {
blacklistScraping: []
};
6 changes: 4 additions & 2 deletions src/bin/prepare-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { env } from 'process';
const parseSrcset = require('parse-srcset');
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
import { PrepareContentConfig } from './prepare-content-config';
require('dotenv').config();

// Function to read all MD files from a directory
Expand All @@ -24,7 +25,7 @@ async function readMdFilesFromDirectory(directoryPath: string): Promise<string[]
}

const [, link] = LinkRegex.exec(markdown) ?? [null, null];
if (link) {
if (link && PrepareContentConfig.blacklistScraping.every(blacklist => !link.includes(blacklist))) {
const scraped = await fetch(link).then(response => response.text());
const { document }: { document: HTMLElement } = new JSDOM(scraped).window;

Expand Down Expand Up @@ -118,7 +119,8 @@ function enrichWithScrapedData(markdown: string, document: HTMLElement) {

if (scrapedTitle) {
if (mdTitle) {
markdown = markdown.replace(mdTitle, scrapedTitle);
// Used to overwrite with scraped title. Caused issues with some scrapes
// markdown = markdown.replace(mdTitle, scrapedTitle);
} else {
markdown = addElement(markdown, 'Title', scrapedTitle);
}
Expand Down

0 comments on commit 0fb3ae9

Please sign in to comment.