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

Website - Different links for different file types #1596

Closed
danscime opened this issue Jun 21, 2019 · 19 comments
Closed

Website - Different links for different file types #1596

danscime opened this issue Jun 21, 2019 · 19 comments
Assignees

Comments

@danscime
Copy link
Collaborator

As per @JacquesCarette's comments in #1527.

Screen Shot 2019-06-21 at 11 10 10 AM

@danscime danscime self-assigned this Jun 21, 2019
@danscime
Copy link
Collaborator Author

@Mornix I'm trying to figure out what's exactly going on here, especially what happens right after field "url". I'm thinking if I can figure it out, I can make a urlPDF and a urlHTML and then name the example once but have 2 separate links to the different versions of the SRS.

Screen Shot 2019-06-21 at 3 53 36 PM

@Mornix
Copy link
Collaborator

Mornix commented Jun 21, 2019

The field “url” line constructs a URL path from the srsPath function. All of the itemBody/makeItem wrapping and unwrapping are to get the value out lift it back into a Compiler (Item a). The input to the url field (and all under the list field srs) is a tuple of the srs field of the Example type, and the whole example.

Let me know if anything is unclear or doesn’t make sense.

@danscime
Copy link
Collaborator Author

Still not entirely sure about how exactly the monads are manipulating things. But, after staring at the screen for a while, I actually found a MUCH easier fix in the index.html file.

Updated in: 0588ab3

Drasil

@JacquesCarette
Copy link
Owner

Minor thing - can you not center the Haskell Documentation link? And maybe add a tiny bit of documentation as to what that links to?

@danscime
Copy link
Collaborator Author

@Mornix could you help explain line 72 here. I'm thinking of having the file list the different subfolders under src in order to have links to the different generated languages.

copy_examples() {
rm -r "$EXAMPLE_DEST"
for example in "$CUR_DIR$BUILD_FOLDER"*; do
example_name=$(basename "$example")
mkdir -p "$EXAMPLE_DEST$example_name/$SRS_DEST"
if [ -d "$example/"SRS ]; then
cp "$example/"SRS/*.pdf "$EXAMPLE_DEST$example_name/$SRS_DEST"
fi
if [ -d "$example/"Website/ ]; then
cp -r "$example/"Website/. "$EXAMPLE_DEST$example_name/$SRS_DEST"
fi
if [ -d "$example/"src ]; then
# We don't expose code in deploy. It's more conveneient to link to GitHub's directory
# We place a stub file which Hakyll will replace.
echo $(cd "$CUR_DIR" && "$MAKE" deploy_code_path | grep "$example_name" | cut -d"$DEPLOY_CODE_PATH_KV_SEP" -f 2-) > "$EXAMPLE_DEST$example_name/src"
fi
done
}

@danscime
Copy link
Collaborator Author

@JacquesCarette for sure! That will be tracked updated and tracked via #1597.

@Mornix
Copy link
Collaborator

Mornix commented Jun 24, 2019

Line 72 calls the deploy_code_path folder target in the Makefile (as the Makefile knows more about the general path setup of Drasil). The grep and cut extract the src path for $example from what’s output by the Makefile.

A likely good option is to store the result of the cut as a variable and combine it with the list of folders inside the returned directory.

@danscime
Copy link
Collaborator Author

By using these 3 lines and commenting out the old line, I can get my desired functionality.

Screen Shot 2019-06-24 at 12 13 34 PM

Which gives in the src file:

Screen Shot 2019-06-24 at 12 13 14 PM

@Mornix
Copy link
Collaborator

Mornix commented Jun 24, 2019

You should be able to achieve exactly the same output by replacing echo in the line you commented out with:
ls -d “$CUR_DIR”$(...)* > ...

Which has the added benefit of avoiding location side-effects and hardcoded information.

@danscime
Copy link
Collaborator Author

danscime commented Jun 24, 2019

I have tried these but none work.

ls -d "$CUR_DIR"$(cd "$CUR_DIR" && "$MAKE" deploy_code_path | grep "$example_name" | cut -d"$DEPLOY_CODE_PATH_KV_SEP" -f 2-)* > "$EXAMPLE_DEST$example_name/src"

ls -d $(cd "$CUR_DIR" && "$MAKE" deploy_code_path | grep "$example_name" | cut -d"$DEPLOY_CODE_PATH_KV_SEP" -f 2-)* > "$EXAMPLE_DEST$example_name/src"

ls -d $("$MAKE" deploy_code_path | grep "$example_name" | cut -d"$DEPLOY_CODE_PATH_KV_SEP" -f 2-)* > "$EXAMPLE_DEST$example_name/src"

@Mornix
Copy link
Collaborator

Mornix commented Jun 24, 2019

Looking at what I wrote, is the line I suggested just printing the languages and not the prefix path? If so, I think some xargs should be able to correct that. However, I’m not great at writing xargs commands off the top of my head.

@danscime
Copy link
Collaborator Author

They all fail as a directory is not found. The first suggestion tries to get into the ...../code/code /.... folder which doesn't exist. Weird.

@Mornix
Copy link
Collaborator

Mornix commented Jun 24, 2019

Right. deploy_code_path gives a path relative to the repo root.

ls -d “$(git rev-parse --show-toplevel)$(...)”* > ...

@Mornix
Copy link
Collaborator

Mornix commented Jun 24, 2019

The rev-parse I just posted will definitely require some fixup with xargs.

@Mornix
Copy link
Collaborator

Mornix commented Jun 25, 2019

Worked out the command line:

ls -d "$(git rev-parse --show-toplevel)/$(make deploy_code_path | grep "glassbr" | cut -d: -f2-)"*/ | rev | cut -d/ -f2 | rev | tr '\n' '\0' | xargs -0 printf "$(make deploy_code_path | grep "glassbr" | cut -d: -f2-)%s\n"

(Which you can run directly to verify the output is as expected.)

Where it could be abstracted to and placed in the script as:

REL_PATH=$(cd "$CUR_DIR" && "$MAKE" deploy_code_path | grep "$example_name" | cut -d"$DEPLOY_CODE_PATH_KV_SEP" -f 2-)
ls -d "$(git rev-parse --show-toplevel)/$REL_PATH"*/ | rev | cut -d/ -f2 | rev | tr '\n' '\0' | xargs -0 printf "$REL_PATH%s\n" > "$EXAMPLE_DEST$example_name/src" 

@danscime
Copy link
Collaborator Author

danscime commented Jun 25, 2019

So for the I'm not entirely sure how to make the required functions.
I'm guessing I should use a list of tuples, where each tuple is (path, language).
Just not sure how to implement.

Screen Shot 2019-06-25 at 4 17 02 PM

EDIT:

I'm currently working on these functions and I think I have found a good way to create them.

@danscime
Copy link
Collaborator Author

As of d77b0ec I have added different links for each generated language. The only problem now is that the "Generated Code" heading appears for each example.

Drasil

I think this is due to the $if(src)$ not being taken into account as they are probably only used by maybeField.

Two possible solutions I can think of right now:

  • Make a separate maybeField that is used pretty much just like a boolean to see if there is existence of code.
  • Make a maybeListFieldFunction that handles both the if and the for aspects of the field.

Not sure which would be more desired. Or maybe there is another solution I cannot think of.

@smiths
Copy link
Collaborator

smiths commented Jun 27, 2019

@JacquesCarette may feel otherwise, but the empty generated code links don't bother me. Eventually we will fill them in. This gives us a reminder that we haven't done this yet. It doesn't seem like something that we should stress over.

@danscime
Copy link
Collaborator Author

danscime commented Jul 2, 2019

"Generated Code" section removed if no example does not have source code via db5ff51

Once this has been merged in, the issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants