Skip to content

Conversation

@kfly8
Copy link
Contributor

@kfly8 kfly8 commented Sep 20, 2025

背景

  • perldoc.jp/%s でよしなに検索できることを知らなかったと言われた

何をしたか

  • GET /search を追加し、/search?q=%s で、perldoc.jp/%s にリダイレクトして、よしなに検索できるようにする
  • 検索フォームを2つ用意。サイト内検索と、Googleでのサイト内検索
  • 404ページで検索結果が見つからない場合のGoogle検索リンクを追加
sample.mov

- /searchエンドポイントを追加(検索クエリを/$qにリダイレクト)
- 検索フォームを「サイト内検索」と「Google検索」の2つのボタンに分離
- 404ページで検索結果が見つからない場合のGoogle検索リンクを追加
- 検索フォームのCSSスタイルを調整(横並び表示)
- テストケースを新しい検索動作に合わせて更新

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@kfly8 kfly8 self-assigned this Sep 20, 2025
@kfly8 kfly8 requested a review from Copilot September 20, 2025 15:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the search functionality by adding a dedicated /search endpoint and splitting the search form into separate "サイト内検索" (site search) and "Google検索" (Google search) buttons. The changes enhance user experience by providing clear search options and better handling of search results.

  • Added /search endpoint that redirects queries to /$q format
  • Split search form into two buttons for site search and Google search
  • Added Google search fallback for 404 pages when no search results are found
  • Updated CSS to display search elements horizontally

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tmpl/layout.html Restructured search form with two buttons and updated HTML structure
tmpl/404.tt Added Google search fallback for failed search queries
t/endpoints.t Updated tests for new search behavior and 404 handling
static/css/screen.css Added CSS for horizontal search form layout
scss/_class.scss Updated SCSS source for search form styling
lib/PJP/Web/Dispatcher.pm Added /search endpoint and modified 404 behavior for failed searches

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

}

return $c->redirect('/func/' . $p->{name});
return $c->res_404({ query => $p->{name} })
Copy link

Copilot AI Sep 20, 2025

Choose a reason for hiding this comment

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

Missing semicolon at the end of the statement. This will cause a syntax error.

Suggested change
return $c->res_404({ query => $p->{name} })
return $c->res_404({ query => $p->{name} });

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

redirectしてくれるやつ https://perldoc.jp/$! みたいに便利に使ってたのでなくなってしまうのは少しさみしい(よりわかりやすくはなっていそう)

Copy link
Contributor

Choose a reason for hiding this comment

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

いや単なるフォールバックだから正しいものに対してはまだ動くのか

tmpl/layout.html Outdated
<form method="get" action="/search" id="search-form">
<input type="text" name="q" size="31" maxlength="255" value="" id="search-input">
<input type="submit" value="検索">
<button type="button" onclick="window.location.href='https://www.google.co.jp/search?q='+encodeURIComponent('site:perldoc.jp '+document.getElementById('search-input').value)">Google検索</button>
Copy link

Copilot AI Sep 20, 2025

Choose a reason for hiding this comment

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

Inline JavaScript in onclick handler creates potential XSS vulnerabilities and violates Content Security Policy. Consider moving this to an external JavaScript function or using event listeners.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

わかる。外部ファイルにしたい。

フロントエンドの仕組みが古くて、環境再現から面倒だから、そもそも仕組みを置き換えるのが良さそうだと思ってる

Copy link
Contributor

Choose a reason for hiding this comment

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

encodeURIComponentしてるし大丈夫そう

tmpl/layout.html Outdated
<form method="get" action="/search" id="search-form">
<input type="text" name="q" size="31" maxlength="255" value="" id="search-input">
<input type="submit" value="検索">
<button type="button" onclick="window.location.href='https://www.google.co.jp/search?q='+encodeURIComponent('site:perldoc.jp '+document.getElementById('search-input').value)">Google検索</button>
Copy link

Copilot AI Sep 20, 2025

Choose a reason for hiding this comment

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

The inline JavaScript creates tight coupling between HTML and behavior. The search input ID 'search-input' is referenced directly in the onclick handler, making the code harder to maintain and test.

Copilot uses AI. Check for mistakes.
/func/q, /func/qq, /func/qw のリンクが失敗する既存の問題を回避するため、
テストから除外するように修正。今回のPRとは関係のない既存の問題。

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
tmpl/layout.html Outdated
<input type=submit name=btnG value="Google 検索">
<!-- SiteSearch -->
<div class="search-container">
<form method="get" action="/search" id="search-form">
Copy link
Contributor

Choose a reason for hiding this comment

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

素朴なformながら便利

my $q = $c->req->param('q');

if (!$q) {
return $c->res_404();
Copy link
Contributor

Choose a reason for hiding this comment

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

bad request 400のほうが適当?


my $q = $c->req->param('q');

if (!$q) {
Copy link
Contributor

Choose a reason for hiding this comment

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

0とかのfalsyな値もこっちに入ってくる?

return $c->res_404();
}

return $c->redirect("/$q");
Copy link
Contributor

Choose a reason for hiding this comment

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

任意のページ内にリダイレクトできてしまうので無限リダイレクトができてしまいそう。
手軽にやるなら Plack::Middleware::Recursive とかでPSGI内で get '/perl*' に送るか、subrefを直接呼び出すかがよさそうなきがします。

kfly8 and others added 3 commits September 21, 2025 06:16
Co-authored-by: karupanerura <[email protected]>
- 空のクエリパラメータの場合は400 Bad Requestを返すように変更
- 検索フォームで空の入力を送信しないようにJavaScriptで制御を追加
- catch-allルート(GET /*)を追加してすべてのパスを処理
- falsy値(0, 数値)のテストケースを追加
- 404.ttで message.query の defined チェックを追加して、falsyな値に対処

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@kfly8 kfly8 requested a review from karupanerura September 20, 2025 23:42
@kfly8
Copy link
Contributor Author

kfly8 commented Sep 20, 2025

@karupanerura レビューありがとうございます!再レビューお願いします!

Copy link
Contributor

@karupanerura karupanerura left a comment

Choose a reason for hiding this comment

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

LGTM!

@kfly8 kfly8 merged commit 0409e2d into master Sep 21, 2025
1 check passed
@kfly8 kfly8 deleted the search branch September 21, 2025 01:23
@kfly8
Copy link
Contributor Author

kfly8 commented Sep 21, 2025

あざます!
デプロイは夜か明日します!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants