[ 
https://issues.apache.org/jira/browse/BEAM-10003?focusedWorklogId=437930&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-437930
 ]

ASF GitHub Bot logged work on BEAM-10003:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 27/May/20 17:46
            Start Date: 27/May/20 17:46
    Worklog Time Spent: 10m 
      Work Description: kgabryje commented on a change in pull request #11796:
URL: https://github.com/apache/beam/pull/11796#discussion_r431327731



##########
File path: website/www/site/layouts/shortcodes/code_sample.html
##########
@@ -0,0 +1,15 @@
+{{/*
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+   http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License. See accompanying LICENSE file.
+*/}}
+{{/*
+  This shortcode is used to fetch a piece of code with tags from Beam code.
+  There should be no breaklines here to make sure the string results do not 
get impacts of newlines.
+*/}}{{ $tag := .Get 1 }}{{ $path := printf "code_samples/%s" (replaceRE "/" 
"_" (.Get 0)) }}{{ $data := readFile $path }}{{ $matchRegex := printf 
"%s%s%s%s%s" "\\[START " $tag "]\n[\\s\\S]*?\n.*\\[END " $tag "]" }}{{ $match 
:= index (findRE $matchRegex $data) 0 }}{{ $lines := split $match "\n" }}{{ 
$lineCount := len $lines }}{{ $cleanedLines := $lines | first (sub $lineCount 
1) | last (sub $lineCount 2) }}{{ $firstLine := index $cleanedLines 0 }}{{ 
$numberOfWhitespaces := index (findRE "^\\s*" $firstLine) 0 | len }}{{ 
$unindentRegex := printf "%s%d%s" "^\\s{" $numberOfWhitespaces "}" }}{{ 
$unindentedLines := apply $cleanedLines "replaceRE" $unindentRegex "" "." }}{{ 
$result := delimit $unindentedLines "\n" }}{{ print $result }}

Review comment:
       In `setupDockerContainer` stage of build process, we run 
`build_code_samples.sh` script, which copies Beam project files from which we 
take code snippets to `website/www/site/code_samples` directory. We do that 
because Hugo can't access files which are outside of its project tree (Hugo's 
root is the directory that contains config.toml). When copying, we name this 
files according to convention `path_to_file_filename.extension` in order to 
avoid name conflicts.
   `.Get 0` references an argument passed to `code_sample` shortcode which is a 
path to file with code snippet. So if you pass `path/to/file/filename.py` to 
code_sample, $path variable will have value 
`code_samples/path_to_file_filename.py` which Hugo can access.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 437930)
    Time Spent: 1h 10m  (was: 1h)

> Need two PR to submit snippets to website
> -----------------------------------------
>
>                 Key: BEAM-10003
>                 URL: https://issues.apache.org/jira/browse/BEAM-10003
>             Project: Beam
>          Issue Type: New Feature
>          Components: website
>            Reporter: Reza ardeshir rokni
>            Assignee: Aizhamal Nurmamat kyzy
>            Priority: P2
>          Time Spent: 1h 10m
>  Remaining Estimate: 0h
>
> Looks like build_github_samples.sh uses code already on the repo to build 
> local serving;
> do
>   fileName=$(echo "$url" | sed -e 's/\//_/g')
>   curl -o "$DIST_DIR"/"$fileName" 
> "[https://raw.githubusercontent.com|https://raw.githubusercontent.com/]$url";
> done
> So when tying to test locally, the code needs to have already be in Beam. 
> Ideally the script should make use of local code when building so :
> 1- Easier to  build & test changes.
> 2- No need to raise two PR for what is a single change
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to