Compare commits

..

No commits in common. "8a00e40402c222119f48792e3ca02bef8857220b" and "a6e397f50b2bed72d448f5bd3e61dd3762169726" have entirely different histories.

10 changed files with 22 additions and 5542 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
/static/ext/
/static/
/scope

View File

@ -6,18 +6,18 @@ build:
.PHONY: build
static:
mkdir -p static/ext
mkdir -p static
wget https://cdn.jsdelivr.net/npm/bulma@0.9.3/css/bulma.min.css -O static/ext/bulma.min.css
wget https://cdn.jsdelivr.net/npm/bulma@0.9.3/css/bulma.min.css -O static/bulma.min.css
wget https://code.iconify.design/2/2.1.0/iconify.min.js -O static/ext/iconify.min.js
wget https://code.iconify.design/2/2.1.0/iconify.min.js -O static/iconify.min.js
wget https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.css -O static/ext/katex.min.css
wget https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.js -O static/ext/katex.min.js
wget https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.css -O static/katex.min.css
wget https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.js -O static/katex.min.js
wget https://cdn.jsdelivr.net/npm/nerdamer@latest/nerdamer.core.js -O static/ext/nerdamer.core.js
wget https://cdn.jsdelivr.net/npm/nerdamer@latest/Algebra.js -O static/ext/Algebra.js
wget https://cdn.jsdelivr.net/npm/nerdamer@latest/Calculus.js -O static/ext/Calculus.js
wget https://cdn.jsdelivr.net/npm/nerdamer@latest/Solve.js -O static/ext/Solve.js
wget https://cdn.jsdelivr.net/npm/nerdamer@latest/nerdamer.core.js -O static/nerdamer.core.js
wget https://cdn.jsdelivr.net/npm/nerdamer@latest/Algebra.js -O static/Algebra.js
wget https://cdn.jsdelivr.net/npm/nerdamer@latest/Calculus.js -O static/Calculus.js
wget https://cdn.jsdelivr.net/npm/nerdamer@latest/Solve.js -O static/Solve.js
wget https://unpkg.com/function-plot/dist/function-plot.js -O static/ext/function-plot.js
wget https://unpkg.com/function-plot/dist/function-plot.js -O static/function-plot.js

View File

@ -93,5 +93,4 @@ This project uses many other projects. Those projects and the reasons for using
- [Nerdamer](https://nerdamer.com/): Equation solver
- [Function Plot](https://mauriciopoppe.github.io/function-plot/): Equation grapher
- [Metaweather](https://www.metaweather.com/): Weather API
- [DuckDuckGo](https://duckduckgo.com/): Provides instant answers
- [Dark Reader](https://darkreader.org/): Dark mode CSS
- [DuckDuckGo](https://duckduckgo.com/): Provides instant answers

View File

@ -26,23 +26,19 @@ import (
)
const calcExtraHead = `
<!-- Import KaTeX for math rendering -->
<link rel="stylesheet" href="/static/ext/katex.min.css">
<script defer src="/static/ext/katex.min.js"></script>
<link rel="stylesheet" href="/static/katex.min.css">
<script defer src="/static/katex.min.js"></script>
<!-- Import Nerdamer for equation evaluator -->
<script src="/static/ext/nerdamer.core.js"></script>
<script src="/static/ext/Algebra.js"></script>
<script src="/static/ext/Calculus.js"></script>
<script src="/static/ext/Solve.js"></script>`
<script src="/static/nerdamer.core.js"></script>
<script src="/static/Algebra.js"></script>
<script src="/static/Calculus.js"></script>
<script src="/static/Solve.js"></script>`
const solveRenderScript = `
<div id="calc-content" class="subtitle mx-2 my-0"></div>
<script>
window.onload = () => {
// Execute input and get output as LaTeX
latex = nerdamer('%s').latex()
// Use KaTeX to render output to #calc-content div
latex = nerdamer.convertToLaTeX(nerdamer('%s').toString())
katex.render(latex, document.getElementById('calc-content'))
}
</script>`

View File

@ -25,7 +25,7 @@ import (
)
const plotExtraHead = `
<script src="/static/ext/function-plot.js"></script>
<script src="/static/function-plot.js"></script>
<style>
.top-right-legend {
display: none;
@ -35,7 +35,6 @@ const plotExtraHead = `
const plotScript = `
<div id="plot-content" class="container"></div>
<script>
// Create function to draw plot in #plot-content
plotFn = () => functionPlot({
target: '#plot-content',
grid: true,
@ -44,7 +43,6 @@ plotFn = () => functionPlot({
fn: '%s'
}]
})
// Create resize observer that runs plot function
new ResizeObserver(plotFn).observe(document.getElementById('plot-content'))
</script>`

View File

@ -6,7 +6,6 @@
name = "Scope"
baseURL = "http://localhost:8080"
sourceURL = "https://gitea.arsenm.dev/Arsen6331/scope"
theme = "dark"
[search]
engines = ["google", "ddg", "bing"]

View File

@ -1,198 +0,0 @@
package web_test
import (
"errors"
"testing"
"go.arsenm.dev/scope/search/web"
)
const (
ErrInNone = iota
ErrInInit
ErrInLink
ErrInTitle
ErrInDesc
)
var (
ErrInit = errors.New("error in init")
ErrLink = errors.New("error in link")
ErrTitle = errors.New("error in title")
ErrDesc = errors.New("error in description")
)
type TestEngine struct {
errIn int
name string
query string
userAgent string
page int
results []TestResult
}
type TestResult struct {
title string
link string
desc string
}
func (te *TestEngine) SetKeyword(query string) {
te.query = query
}
func (te *TestEngine) SetUserAgent(ua string) {
te.userAgent = ua
}
func (te *TestEngine) SetPage(page int) {
te.page = page
}
func (te *TestEngine) Init() error {
if te.errIn == ErrInInit {
return ErrInit
}
te.results = append(te.results,
TestResult{
"Google",
"https://www.google.com",
"Google search engine",
},
TestResult{
"Wikipedia",
"https://wikipedia.org",
"Online wiki encyclopedia",
},
TestResult{
"Reddit",
"https://reddit.com",
"600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars 600 chars ",
},
TestResult{
"Example",
"https://example.com",
"",
},
)
return nil
}
func (te *TestEngine) Each(eachCb func(int) error) error {
for index := range te.results {
if err := eachCb(index); err != nil {
return err
}
}
return nil
}
func (te *TestEngine) Title(i int) (string, error) {
if te.errIn == ErrInTitle {
return "", ErrTitle
}
return te.results[i].title, nil
}
func (te *TestEngine) Link(i int) (string, error) {
if te.errIn == ErrInLink {
return "", ErrLink
}
return te.results[i].link, nil
}
func (te *TestEngine) Desc(i int) (string, error) {
if te.errIn == ErrInDesc {
return "", ErrDesc
}
return te.results[i].desc, nil
}
func (te *TestEngine) Name() string {
return te.name
}
func TestSearch(t *testing.T) {
engine := &TestEngine{name: "one"}
results, err := web.Search(
web.Options{
Keyword: "test keyword",
UserAgent: "TestEngine/0.0.0",
Page: 0,
},
engine,
&TestEngine{name: "two"},
)
if err != nil {
t.Fatalf("Error in Search(): %s", err)
}
if len(results) < len(engine.results)-1 {
t.Fatalf(
"Expected %d results, got %d",
len(engine.results),
len(results),
)
}
for index, result := range results {
if engine.results[index].desc == "" {
continue
}
if result.Title != engine.results[index].title {
t.Fatalf(
"Result %d: expected title %s, got %s",
index,
engine.results[index].title,
result.Title,
)
} else if result.Link != engine.results[index].link {
t.Fatalf(
"Result %d: expected link %s, got %s",
index,
engine.results[index].link,
result.Link,
)
} else if result.Desc != engine.results[index].desc &&
len(engine.results[index].desc) <= 500 {
t.Fatalf(
"Result %d: expected description %s, got %s",
index,
engine.results[index].desc,
result.Desc,
)
}
}
}
func TestSearchError(t *testing.T) {
engines := []*TestEngine{
{errIn: ErrInInit},
{errIn: ErrInTitle},
{errIn: ErrInLink},
{errIn: ErrInDesc},
}
for index, engine := range engines {
_, err := web.Search(
web.Options{
Keyword: "test keyword",
UserAgent: "TestEngine/0.0.0",
Page: 0,
},
engine,
)
if err == nil {
t.Fatalf("Expected error in engine %d, received nil", index)
} else if err != ErrTitle && engines[index].errIn == ErrInTitle {
t.Fatalf("Expected error in title (index %d), received %s", index, err)
} else if err != ErrLink && engines[index].errIn == ErrInLink {
t.Fatalf("Expected error in link (index %d), received %s", index, err)
} else if err != ErrDesc && engines[index].errIn == ErrInDesc {
t.Fatalf("Expected error in description (index %d), received %s", index, err)
} else if err != ErrInit && engines[index].errIn == ErrInInit {
t.Fatalf("Expected error in init (index %d), received %s", index, err)
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -3,11 +3,8 @@
<head>
<title>{{template "page" .}} - {{.Config "site.name"}}</title>
<link rel="search" type="application/opensearchdescription+xml" title='{{.Config "site.name"}}' href="/opensearch">
<link rel="stylesheet" href="/static/ext/bulma.min.css">
<script async src="/static/ext/iconify.min.js"></script>
{{if .Config "site.theme" | ne "light"}}
<link rel="stylesheet" href="/static/DarkReader-scope.css">
{{end}}
<link rel="stylesheet" href="/static/bulma.min.css">
<script async src="/static/iconify.min.js"></script>
{{if .Card}}
{{.Card.Head}}
{{end}}