janet-lang / janet-lang.org

Website for janet
https://janet-lang.org
MIT License
90 stars 58 forks source link

Several (probably all) community examples links of spork functions are broken. #195

Open fnaj77 opened 1 year ago

fnaj77 commented 1 year ago

As per title, I've tested several links in the documentation, and all were broken (404).

Just to be clear, I mean the link to the community examples at the end of each section of spork module.

As an example, the documentation section of spork argparse (https://janet-lang.org/api/spork/index.html#spork/argparse/argparse) has a link to a janetdocs.com page with community examples (https://janetdocs.com/spork/argparse/argparse) that doesn't exist.

I don't know if those links were automatically generated and the corresponding pages never existed or if those pages have been moved.

Thanks for your time and hard work!

sogaiu commented 1 year ago

Yes, I believe:

the corresponding pages never existed

is the case.

It's been a while but IIUC janetdocs supports most of what is bundled with janet itself, but not other bits.

fnaj77 commented 1 year ago

Yes, I believe:

the corresponding pages never existed

is the case.

It's been a while but IIUC janetdocs supports most of what is bundled with janet itself, but not other bits.

Thank you for your reply @sogaiu .

I'm sorry, but I'm learning janet at the moment and I'm not expert enough to contribute proposing correct and idiomatic examples. Should I close this issue or leave it open to keep it more visible?

sogaiu commented 1 year ago

I don't know what might happen regarding whether the reported links should disappear or whether janetdocs might be "extended" or yet another path.

ATM, I think the links to janetdocs may be a result of this line which is part of this repository.

I would say to leave this issue open for the moment, but perhaps other folks have other ideas :)

sogaiu commented 2 months ago

The broken links have been mentioned at the zulip instance.

I don't know what's involved in removing those links. As mentioned in the previous comment, I think this line might be related.

@pepe Do you have any ideas / thoughts?

pepe commented 2 months ago

I am not sure what to do here :-(.

sogaiu commented 2 months ago

It looks like the line in question is part of the return value of emit-item and earlier in the function there is:

https://github.com/janet-lang/janet-lang.org/blob/604b786dac163ce68f0eba7c863e5a7bb879745f/content/api/gen-docs.janet#L88

Looks like the :source-linker dynamic variable is arranged for via an .mdz file, e.g. for spork/base64, like this:

https://github.com/janet-lang/janet-lang.org/blob/e4a7d558caee6e2ebcfd3f9c0ac000511f36f6e1/content/api/spork/base64.mdz#L3

May be emit-item could be modified to check for another dynamic variable that is the name of a module (e.g. spork/base64). The value could be matched on to decide not to have:

{:tag "a" "href" (string "https://janetdocs.com/" (jdoc-escape key)) :content "Community Examples"}

be part of emit-item's return value.

To get this working, all of the spork/*.mdz files would need to change too though.


Perhaps there is a simpler better idea. Not sure what yet though (^^;

sogaiu commented 2 months ago

Ok, I tried something out:

index af064c3..d80122e 100644
--- a/content/api/gen-docs.janet
+++ b/content/api/gen-docs.janet
@@ -86,7 +86,8 @@
                        (type val))
         docstring (remove-extra-spaces docstring)
         source-linker (dyn :source-linker janet-source-linker)
-        example (check-example key)]
+        example (check-example key)
+        c-example (not (dyn :no-community-examples))]
     {:tag "div" "class" "binding"
      :content [{:tag "span" "class" "binding-sym" "id" key :content key} " "
                {:tag "span" "class" "binding-type" :content binding-type} " "
@@ -98,8 +99,10 @@
                ;(if example [{:tag "div" "class" "example-title" :content "EXAMPLES"}
                              {:tag "pre" "class" "mendoza-codeblock"
                               :content {:tag "code" :language (require "janet.syntax") :content (string example)}}] [])
-
-               {:tag "a" "href" (string "https://janetdocs.com/" (jdoc-escape key)) :content "Community Examples"}]}))
+               (if c-example
+                 {:tag "a" "href"
+                  (string "https://janetdocs.com/" (jdoc-escape key))
+                  :content "Community Examples"})]}))

 (defn- all-entries 
   [&opt env]
diff --git a/content/api/spork/base64.mdz b/content/api/spork/base64.mdz
index a3bfb0b..8ff76a5 100644
--- a/content/api/spork/base64.mdz
+++ b/content/api/spork/base64.mdz
@@ -1,6 +1,7 @@
 (import ../gen-docs :as gen-docs)
 (import spork/base64 :export true)
 (setdyn :source-linker (partial gen-docs/github-source-linker "janet-lang/spork" gen-docs/spork-version))
+(setdyn :no-community-examples true)

 {:title "Base64"
  :nav-title "base64"

That seems to sort of work.

sogaiu commented 2 months ago

I guess a similar thing applies to the jpm stuff too, e.g. at the destination such as this.

sogaiu commented 2 months ago

Looks like #221 (an attempt at addressing this issue) was merged, but perhaps it's better to wait for the site to be regenerated before closing this issue (which isn't something I can do anyway :) ).