Skip to content

Commit

Permalink
Merge pull request #68 from perldoc-jp/revert-67-revert-66-revert-65-…
Browse files Browse the repository at this point in the history
…fence

Revert "markdownのFencedCodeに対応する"
kfly8 authored May 16, 2024
2 parents 8f339b8 + e108833 commit 7de308a
Showing 13 changed files with 414 additions and 442 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -15,5 +15,5 @@ jobs:

- name: Run test
run: |
make ci
make test
41 changes: 0 additions & 41 deletions .github/workflows/update-cpanfile-snapshot.yml

This file was deleted.

24 changes: 14 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -6,23 +6,27 @@ RUN apt-get update && \
apt-get -y upgrade && \
apt-get install -y wget gcc g++ make sqlite3

RUN cpm install -g Carton

WORKDIR /usr/src/app

COPY cpanfile cpanfile.snapshot .
COPY cpanfile ./
RUN cpm install
COPY . .

RUN sqlite3 perldocjp.master.db < sql/sqlite.sql
RUN cp perldocjp.master.db perldocjp.slave.db

ENV PLACK_ENV=docker
ENV PERL5LIB=/usr/src/app/local/lib/perl5
ENV PATH=/usr/src/app/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# 翻訳データの更新
RUN perl script/update.pl

FROM base as app

RUN carton install --deployment
COPY . .

RUN sqlite3 perldocjp.master.db < sql/sqlite.sql
RUN cp perldocjp.master.db perldocjp.slave.db

# テスト用のステージ
FROM base as test
RUN cpm install --with-test --with-develop --show-build-log-on-failure

# サーバーを起動したい時のステージ
FROM base as web
CMD ["./local/bin/plackup", "-p", "5000", "-Ilib", "app.psgi"]
24 changes: 6 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@

.PHONY: build
build:
docker compose build
docker-compose -f docker-compose.yml build web

.PHONY: up
up:
docker compose up
make build
docker-compose -f docker-compose.yml up -d web

.PHONY: down
down:
docker compose down
docker-compose -f docker-compose.yml down

.PHONY: test
test: TEST_TARGET = t
test:
docker compose exec app prove -lrv $(TEST_TARGET)

.PHONY: ci
ci:
docker compose up -d
make setup-data
make test

# 翻訳データのセットアップ
# TODO: 翻訳データのセットアップは他にもあるので、全部ひとまとめにできると良さそう
.PHONY: setup-data
setup-data:
docker compose exec app perl script/update.pl

docker-compose -f docker-compose.yml build test
docker-compose -f docker-compose.yml run test prove -Ilib -r -v t
3 changes: 1 addition & 2 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ requires 'DBIx::TransactionManager';
requires 'Regexp::Common';
requires 'Regexp::Assemble';
requires 'Text::Diff::FormattedHTML';
requires 'Text::Markdown::Discount';
requires 'Text::Markdown';
requires 'SQL::Interp';
requires 'Carp::Clan';
requires 'JSON';
@@ -39,5 +39,4 @@ requires 'Log::Minimal';
on 'test' => sub {
requires 'Test2::V0';
requires 'Test::WWW::Mechanize::PSGI';
requires 'Unicode::GCString';
};
659 changes: 367 additions & 292 deletions cpanfile.snapshot

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion cpanfile.target

This file was deleted.

25 changes: 8 additions & 17 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
version: '3'
services:
app:
web:
build:
context: .
target: app
target: web
ports:
- "8080:8080"
command: ./local/bin/plackup -p 8080 -r -Ilib app.psgi
volumes:
- ./config:/usr/src/app/config
- ./data:/usr/src/app/data
- ./lib:/usr/src/app/lib
- ./script:/usr/src/app/script
- ./scss:/usr/src/app/scss
- ./sql:/usr/src/app/sql
- ./static:/usr/src/app/static
- ./t:/usr/src/app/t
- ./tmpl:/usr/src/app/tmpl
- ./xt:/usr/src/app/xt
- ./app.psgi:/usr/src/app/app.psgi
- ./cpanfile:/usr/src/app/cpanfile
- "8080:5000"

test:
build:
context: .
target: test

9 changes: 2 additions & 7 deletions lib/PJP.pm
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package PJP;
use strict;
use warnings;
use feature qw(state);
use parent qw/Amon2/;
our $VERSION='0.01';
use 5.01000;

use PJP::Util qw(markdown_to_html);

use Amon2::Config::Simple;
sub load_config { Amon2::Config::Simple->load(shift) }

@@ -61,12 +58,10 @@ sub abstract_title_description_from_md {
($abstract) = $1;
}
if ($abstract) {
$abstract = markdown_to_html($abstract);
$abstract = Text::Markdown->new->markdown($abstract);
($abstract) = $abstract =~ m{^<p>(.+?)</p>};
}
if ($abstract) {
$abstract =~ s{<.*?>}{}g;
}
$abstract =~ s{<.*?>}{}g;
return ($title, $abstract);
}

6 changes: 3 additions & 3 deletions lib/PJP/M/PodFile.pm
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use strict;
use warnings;
use utf8;
use feature qw(state);

package PJP::M::PodFile;
use Amon2::Declare;
@@ -13,7 +12,7 @@ use File::Basename;
use version;
use PJP::M::Index::Article;
use PJP::M::BuiltinFunction;
use PJP::Util qw(markdown_to_html);
use Text::Markdown;

sub slurp {
my ($class, $path) = @_;
@@ -278,7 +277,8 @@ sub generate_one_file_md {

$package or die "cannot get package name: $relpath";

my $html = markdown_to_html($md_src);
my $md = Text::Markdown->new;
my $html = $md->markdown($md_src);

$distvname =~ s!/.+!!;
+{
23 changes: 1 addition & 22 deletions lib/PJP/Util.pm
Original file line number Diff line number Diff line change
@@ -2,12 +2,9 @@ package PJP::Util;

use strict;
use warnings;
use feature qw(state);
use parent 'Exporter';

use Text::Markdown::Discount ();

our @EXPORT_OK = qw/slurp markdown_to_html/;
our @EXPORT_OK = qw/slurp/;

sub slurp {
if (@_==1) {
@@ -19,23 +16,5 @@ sub slurp {
}
}

sub markdown_to_html {
my ($markdown) = @_;

state $flag = Text::Markdown::Discount::MKD_NOHEADER
| Text::Markdown::Discount::MKD_NOPANTS
| 0x02000000 # MKD_FENCEDCODE
;

my $html = Text::Markdown::Discount::markdown($markdown, $flag);

# perldoc.jp 用の加工
$html =~ s{^.*<(?:body)[^>]*>}{}si;
$html =~ s{</(?:body)>.*$}{}si;
$html =~ s{<!--\s+original(.*?)-->}{<div class="original">$1</div>}sg;

return $html;
}

1;

15 changes: 11 additions & 4 deletions lib/PJP/Web/Dispatcher.pm
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ package PJP::Web::Dispatcher;
use strict;
use warnings;
use utf8;
use feature qw(state);

use Amon2::Web::Dispatcher::Lite;

@@ -11,15 +10,14 @@ use File::stat;
use Try::Tiny;
use Text::Xslate::Util qw/mark_raw/;

use PJP::Util qw(markdown_to_html);
use PJP::M::TOC;
use PJP::M::Index::Module;
use PJP::M::Index::Article;
use PJP::M::Pod;
use PJP::M::PodFile;
use Regexp::Common qw/URI/;
use URI::Escape qw/uri_escape/;
use Encode qw(decode_utf8);
use Text::Markdown;

get '/' => sub {
my $c = shift;
@@ -375,7 +373,16 @@ get '/docs/{path:articles/.+\.md}' => sub {
my $src = PJP::M::PodFile->slurp($p->{path}) // return $c->res_404();

my ($title, $abstract) = $c->abstract_title_description_from_md($src);
my $html = markdown_to_html($src);
my $md = Text::Markdown->new;
my $html = $md->markdown($src);

$html =~ s{^.*<(?:body)[^>]*>}{}si;
$html =~ s{</(?:body)>.*$}{}si;
$html =~ s{\n<!--\s+original(.*?)-->\n}{<div class="original">$1</div>}sg;
$html =~ s{~~~(?:\s*(sh|perl)\s+)?(.+?)\s*~~~}
{'<pre class="prettyprint ' . ($1 ? ' lang-' . $1 : ''). qq{"><code>$2</code></pre>}}seg;
$html =~ s{<p>```</p>\s*<blockquote>\s*<p>(?:\s*(sh|perl)\s+)?(.+?)```</p>\s*</blockquote>}
{'<pre class="prettyprint ' . ($1 ? ' lang-' . $1 : ''). qq{"><code>$2</code></pre>}}seg;

return $c->render('pod.tt',
{
24 changes: 0 additions & 24 deletions t/Util.t

This file was deleted.

0 comments on commit 7de308a

Please sign in to comment.