Coder Social home page Coder Social logo

Is it possible to have directories? about rib HOT 6 CLOSED

srid avatar srid commented on June 16, 2024
Is it possible to have directories?

from rib.

Comments (6)

srid avatar srid commented on June 16, 2024

Yes, Rib should already do this. In a private project of mine I have a/2019/12/25.md => b/2019/12/25.html which is done by this code:

entries <-
  Rib.buildHtmlMulti M.parse [[relfile|*/*/*.md|]] $ renderPage . Target_Page

Does it not already work for you? If so, could you show your code?

from rib.

srid avatar srid commented on June 16, 2024

Rib uses Development.Shake.FilePattern, which also supports ** (double star) to match an arbitrary number of path components. You can see that Rib already uses this to copy over static files:

Rib.buildStaticFiles [[relfile|static/**|]]

from rib.

JonathanReeve avatar JonathanReeve commented on June 16, 2024

When using the Rib sample pattern, like this:

    generateSite = do
      -- Copy over the static files
      Rib.buildStaticFiles [[relfile|static/**|]]
      -- Build individual markup sources, generating .html for each.
      docs <- Rib.buildHtmlMulti patterns $ renderPage . Page_Doc

      -- Build an index.html linking to the aforementioned files.
      Rib.buildHtml [relfile|index.html|] $ renderPage $ Page_Index docs

    -- File patterns to build, using the associated markup parser
    patterns = Map.fromList [ ([relfile|**/*.md|], Some Rib.Markup_MMark)]

It throws the error:

* Raised the exception:
dist/about/index.html: openFile: does not exist (No such file or directory)

...which is unusual, because of course it doesn't exist yetβ€”it hasn't built it yet. I get the same error when I use */*.md as the pattern.

from rib.

JonathanReeve avatar JonathanReeve commented on June 16, 2024

The site I'm trying to build is here. It has pages like about/index.md and texts/index.md. Maybe there could be a rule in Shake that would allow for pretty URLs? That is, rendering /about.md as /about/index.html as in Jekyll.

from rib.

srid avatar srid commented on June 16, 2024

The site I'm trying to build is here.

This is most useful to share; thanks!

dist/about/index.html: openFile: does not exist (No such file or directory)

This was bug #63 that got fixed recently. Advancing rib in default.nix should resolve it; I opened a PR here: open-editions/open-editions.org#3

It has pages like about/index.md and texts/index.md. Maybe there could be a rule in Shake that would allow for pretty URLs? That is, rendering /about.md as /about/index.html as in Jekyll.

This is certainly doable. Rib assumes that /foo/bar.md will map to /foo/bar.html. buildHtmlMulti is defined in a handful of lines like this:

buildHtmlMulti parser pats r = do
  input <- ribInputDir
  fs <- getDirectoryFiles' input pats
  forP fs $ \k -> do
    outfile <- liftIO $ replaceExtension ".html" k
    buildHtml parser outfile k r

Note that outfile is same as source path, except for file extension. You can basically copy paste this function in your Main.hs and customize it however you want. I gave it a go here: open-editions/open-editions.org#5

I suppose buildHtmlMulti can be customized to take a function FilePath -> FilePath that determines this outfile. Or, better FilePath -> Slug using the slug type (basically a newtype over FilePath) proposed by @joelmccracken in Rib chat room at Zulip.

from rib.

JonathanReeve avatar JonathanReeve commented on June 16, 2024

Thanks for the PR! This is great.

from rib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.