Skip to content

Commit

Permalink
Merge branch 'maxim-top:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ericliang authored Jun 22, 2024
2 parents f5942cc + edb5b09 commit 7da867d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions scripts/subdirectory_summary.escript
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,17 @@ links_title(BaseDir) ->
make_relative_link(ParentLink, Link) ->
PUrl = markdown_to_html_url(ParentLink),
Url = markdown_to_html_url(Link),
calculate_relative_path(PUrl, Url).
Res = calculate_relative_path(PUrl, Url),
Res2 = markdown_to_html_url_remove_readme(Res),
io:format("make_relative_link: ParentLink: ~p, Link: ~p, PUrl: ~p, Url: ~p, Res: ~p, Res2:~p~n", [ParentLink, Link, PUrl, Url, Res, Res2]),
Res2.

calculate_relative_path(From, To) ->
FromAdjusted = ensure_trailing_slash(From),
ToAdjusted = ensure_trailing_slash(To),
FromList = string:tokens(FromAdjusted, "/"),
ToList = string:tokens(ToAdjusted, "/"),
{_, FromSuffix, ToSuffix} = find_common_path(FromList, ToList, [], []),
{CommonPath, FromSuffix, ToSuffix} = find_common_path(FromList, ToList, [], []),
UpSteps = max(0, length(FromSuffix) - 1),
UpPath = lists:duplicate(UpSteps, ".."),
RelativePathList = UpPath ++ ToSuffix,
Expand Down Expand Up @@ -122,11 +125,15 @@ markdown_to_html_file(File) ->
Bin2 = binary:replace(Bin1, <<".md">>, <<".html">>),
"_book/"++binary_to_list(Bin2).

markdown_to_html_url_remove_readme(File) ->
Bin = iolist_to_binary(File),
Bin1 = binary:replace(Bin, <<"README.html">>, <<"">>),
binary_to_list(Bin1).

markdown_to_html_url(File) ->
Bin = iolist_to_binary(File),
Bin1 = binary:replace(Bin, <<"README.md">>, <<"">>),
Bin2 = binary:replace(Bin1, <<".md">>, <<".html">>),
"_book/"++binary_to_list(Bin2).
Bin2 = binary:replace(Bin, <<".md">>, <<".html">>),
binary_to_list(Bin2).

parse_line(Line) ->
{match, [[_, {TitleStart, TitleLen},{LinkStart, LinkLen}]]} = re:run(Line, "\\[(.*)\\]\\((.*)\\)", [global]),
Expand Down

0 comments on commit 7da867d

Please sign in to comment.