Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions nix/frontend.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ stdenv.mkDerivation (finalAttrs: {
postPatch = ''
substituteInPlace src/index.html \
--replace-fail '##TITLE##' ${lib.escapeShellArg config.title}
substituteInPlace public/opensearch-options.xml public/opensearch-packages.xml \
--replace-fail '##TITLE##' ${lib.escapeShellArg config.title}
Comment thread
SuperSandro2000 marked this conversation as resolved.

# remove development files
rm -rf public/data
Expand Down
8 changes: 8 additions & 0 deletions public/opensearch-options.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>##TITLE## - Options</ShortName>
<Description>##TITLE## options search</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16" type="image/x-icon">favicon.ico</Image>
<Url type="text/html" template="./options?query={searchTerms}" />
</OpenSearchDescription>
8 changes: 8 additions & 0 deletions public/opensearch-packages.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>##TITLE## - Packages</ShortName>
<Description>##TITLE## packages search</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16" type="image/x-icon">favicon.ico</Image>
<Url type="text/html" template="./packages?query={searchTerms}" />
</OpenSearchDescription>
18 changes: 18 additions & 0 deletions src/app/core/opensearch-link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { CONFIG } from './config.domain';

export type OpenSearchType = 'options' | 'packages';

export function setOpenSearchLink(document: Document, type: OpenSearchType): void {
const existing = document.head.querySelector<HTMLLinkElement>('link[data-nuschtos-opensearch]');
const link = existing ?? document.head.appendChild(document.createElement('link'));

link.rel = 'search';
link.type = 'application/opensearchdescription+xml';
link.dataset.nuschtosOpensearch = 'true';
link.title = `${CONFIG.title} ${type === 'options' ? 'Options' : 'Packages'} Search`;
link.href = `${CONFIG.baseHref}opensearch-${type}.xml`;
}

export function clearOpenSearchLink(document: Document): void {
document.head.querySelector<HTMLLinkElement>('link[data-nuschtos-opensearch]')?.remove();
}
8 changes: 6 additions & 2 deletions src/app/pages/options/options-page.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ChangeDetectionStrategy, Component, Inject, LOCALE_ID, OnDestroy } from '@angular/core';
import { CONFIG } from '../../core/config.domain';
import { DOCUMENT } from '@angular/common';
import { OptionComponent } from '../../core/components/option/option.component';
import { OptionsService } from '../../core/data/options.service';
import { OptionsSearchComponent } from '../../core/components/search/search.component';
import { RouterLink } from '@angular/router';
import { AsyncPipe, DecimalPipe, formatNumber } from '@angular/common';
import { AsyncPipe, formatNumber } from '@angular/common';
import { BehaviorSubject, Subject, takeUntil } from 'rxjs';
import { clearOpenSearchLink, setOpenSearchLink } from '../../core/opensearch-link';

@Component({
selector: 'app-options',
Expand All @@ -27,15 +28,18 @@ export class OptionsPageComponent implements OnDestroy {

constructor(
protected readonly searchService: OptionsService,
@Inject(DOCUMENT) private readonly document: Document,
@Inject(LOCALE_ID) private readonly locale: string
) {
setOpenSearchLink(this.document, 'options');
this.searchService.getIndexSize()
.pipe(takeUntil(this.destroy$))
.subscribe(size => {
this.searchLabel$.next(`Search ${formatNumber(size ?? 0, this.locale)} options`);
});
}
ngOnDestroy(): void {
clearOpenSearchLink(this.document);
this.destroy$.next();
this.destroy$.complete();
}
Expand Down
5 changes: 5 additions & 0 deletions src/app/pages/packages/packages-page.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { ChangeDetectionStrategy, Component, Inject, LOCALE_ID, OnDestroy } from '@angular/core';
import { DOCUMENT } from '@angular/common';
import { PackagesSearchComponent } from '../../core/components/search/search.component';
import { PackagesService } from '../../core/data/packages.service';
import { PackageComponent } from "../../core/components/package/package.component";
import { AsyncPipe, formatNumber } from '@angular/common';
import { BehaviorSubject, Subject, takeUntil } from 'rxjs';
import { clearOpenSearchLink, setOpenSearchLink } from '../../core/opensearch-link';

@Component({
selector: 'app-packages-page.component',
Expand All @@ -23,15 +25,18 @@ export class PackagesPageComponent implements OnDestroy {

constructor(
protected readonly searchService: PackagesService,
@Inject(DOCUMENT) private readonly document: Document,
@Inject(LOCALE_ID) private readonly locale: string
) {
setOpenSearchLink(this.document, 'packages');
this.searchService.getIndexSize()
.pipe(takeUntil(this.destroy$))
.subscribe(size => {
this.searchLabel$.next(`Search ${formatNumber(size ?? 0, this.locale)} packages`);
});
}
ngOnDestroy(): void {
clearOpenSearchLink(this.document);
this.destroy$.next();
this.destroy$.complete();
}
Expand Down
Loading