Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sourceUrl: strip index.html #81

Merged
merged 2 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions src/Rib/Shake.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ buildHtml ::
(Source repr -> Html ()) ->
Action (Source repr)
buildHtml parser outfile k r = do
let relUrl = toText $ toFilePath ([absdir|/|] </> outfile)
src <- Source k relUrl <$> readSource parser k
src <- Source k outfile <$> readSource parser k
writeHtml outfile $ r src
pure src

Expand Down
16 changes: 12 additions & 4 deletions src/Rib/Source.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ module Rib.Source
)
where

import qualified Data.Text as T
import Development.Shake (Action)
import Path
import Relude

-- | A source file on disk
data Source repr
= Source
{ -- | Path to the source; relative to the source directory.
{ -- | Path to the source; relative to `ribInputDir`
_source_path :: Path Rel File,
-- | Relative URL (begins with `/`) to the generated HTML file
_source_url :: Text,
-- | Path to the generated HTML file; relative to `ribOutputDir`
_source_builtPath :: Path Rel File,
-- | Parsed representation of the source.
_source_val :: repr
}
Expand All @@ -38,8 +39,15 @@ data Source repr
sourcePath :: Source repr -> Path Rel File
sourcePath = _source_path

-- | Relative URL to the generated source HTML.
sourceUrl :: Source repr -> Text
sourceUrl = _source_url
sourceUrl = stripIndexHtml . relPathToUrl . _source_builtPath
where
relPathToUrl = toText . toFilePath . ([absdir|/|] </>)
stripIndexHtml s =
if T.isSuffixOf "index.html" s
then T.dropEnd (T.length $ "index.html") s
else s

sourceVal :: Source repr -> repr
sourceVal = _source_val
Expand Down