I am using Jekyll and Markdown on Github for my blog. How do I insert code tags in my page? - github

I am using Jekyll and Markdown on Github for my blog. How do I insert code tags in my page?
example I was thinking I can use the <pre> tags to insert some code snaps into my page to display to the readers but jekyll does not like them..
Can someone please tell me a good formatting tag I can use with this to insert code in my page
if I try this code:
<pre>
<code class="ruby">
git clone --mirror git#git.com:project project
cd project
git remote add github git#github.com:username/project.git
In cron Job
cd /pathto/project && git fetch -q && git push -q --mirror github
</code>
</pre>
I get this error
My _config.xml
# This is the default format.
# For more see: https://github.com/mojombo/jekyll/wiki/Permalinks
permalink: /:categories/:year/:month/:day/:title
exclude: [".rvmrc", ".rbenv-version", "README.md", "Rakefile", "changelog.md"]
auto: true
pygments: true
# Themes are encouraged to use these universal variables
# so be sure to set them if your theme uses them.
#
title : xxxx
tagline :xxxx
author :
name : xxx
email : jxxx
github : xxx
twitter : xx
# The production_url is only used when full-domain names are needed
# such as sitemap.txt
# Most places will/should use BASE_PATH to make the urls
#
# If you have set a CNAME (pages.github.com) set your custom domain here.
# Else if you are pushing to username.github.com, replace with your username.
# Finally if you are pushing to a GitHub project page, include the project name at the end.
#
production_url : http://johnathanmarksmith.com
# All Jekyll-Bootstrap specific configurations are namespaced into this hash
#
JB :
version : 0.3.0
# All links will be namespaced by BASE_PATH if defined.
# Links in your website should always be prefixed with {{BASE_PATH}}
# however this value will be dynamically changed depending on your deployment situation.
#
# CNAME (http://yourcustomdomain.com)
# DO NOT SET BASE_PATH
# (urls will be prefixed with "/" and work relatively)
#
# GitHub Pages (http://username.github.com)
# DO NOT SET BASE_PATH
# (urls will be prefixed with "/" and work relatively)
#
# GitHub Project Pages (http://username.github.com/project-name)
#
# A GitHub Project site exists in the `gh-pages` branch of one of your repositories.
# REQUIRED! Set BASE_PATH to: http://username.github.com/project-name
#
# CAUTION:
# - When in Localhost, your site will run from root "/" regardless of BASE_PATH
# - Only the following values are falsy: ["", null, false]
# - When setting BASE_PATH it must be a valid url.
# This means always setting the protocol (http|https) or prefixing with "/"
BASE_PATH : false
# By default, the asset_path is automatically defined relative to BASE_PATH plus the enabled theme.
# ex: [BASE_PATH]/assets/themes/[THEME-NAME]
#
# Override this by defining an absolute path to assets here.
# ex:
# http://s3.amazonaws.com/yoursite/themes/watermelon
# /assets
#
ASSET_PATH : false
# These paths are to the main pages Jekyll-Bootstrap ships with.
# Some JB helpers refer to these paths; change them here if needed.
#
archive_path: /archive.html
categories_path : /categories.html
tags_path : /tags.html
atom_path : /atom.xml
rss_path : /rss.xml
# Settings for comments helper
# Set 'provider' to the comment provider you want to use.
# Set 'provider' to false to turn commenting off globally.
#
comments :
provider : disqus
disqus :
short_name : jekyllbootstrap
livefyre :
site_id : 123
intensedebate :
account : 123abc
facebook :
appid : 123
num_posts: 5
width: 580
colorscheme: light
# Settings for analytics helper
# Set 'provider' to the analytics provider you want to use.
# Set 'provider' to false to turn analytics off globally.
#
analytics :
provider : google
google :
tracking_id : 'UA-123-12'
getclicky :
site_id :
mixpanel :
token : '_MIXPANEL_TOKEN_'
# Settings for sharing helper.
# Sharing is for things like tweet, plusone, like, reddit buttons etc.
# Set 'provider' to the sharing provider you want to use.
# Set 'provider' to false to turn sharing off globally.
#
sharing :
provider : false
# Settings for all other include helpers can be defined by creating
# a hash with key named for the given helper. ex:
#
# pages_list :
# provider : "custom"
#
# Setting any helper's provider to 'custom' will bypass the helper code
# and include your custom code. Your custom file must be defined at:
# ./_includes/custom/[HELPER]
# where [HELPER] is the name of the helper you are overriding.

If the "page" you are referring to is a Markdown file, i.e. the extension is .md or .markdown, then you'll want to use the standard Markdown syntax:
For inline code use backticks, like this: `inline code`
For block code indent each line by 4 spaces:
block
of
code
Jekyll uses a Markdown parser like RedCarpet, Maruku or RDiscount and doesn't define how you should format your content, that's set by the type of content you are writing, in this case, Markdown. So the place to look is the Markdown syntax documentation for code:
http://daringfireball.net/projects/markdown/syntax#code
You might also look into Syntax highlighting using the {% highlight %} Liquid syntax tag:
https://github.com/mojombo/jekyll/wiki/Liquid-Extensions#code-highlighting
Hope that helps!

How about this sir
~~~ ruby
# This is a test.
def foo
puts 'foo'
end
~~~
ref

Related

Github not navigating properly to the markdown header link

We are on Github Enterprise
I have created a md file with several headers like
# test
## subtest
# test1
## subtest1
# test2
## subtest2
# test3
## subtest3
Now when the md file is rendered in github .I create a link by right clicking on the #test 2 header and copy the link address.
I am navigated to somewhere in the content of #test header
Similarly all the header links naivgation are inconsistently behaving.
Best Regards,
Saurav

Where can I get NPM package information from a Github Repository?

I want to be able to get a few information about NPM packages in a Javascript based repository on Github.
I want to believe I can see them from the package.json file the repositories.
Please any help or guideline on this?.
I will like to extract the needed information using powershell from the file.
Determine the URL for the raw content of the package.json file of interest:
E.g., for the json5 package, click on the Repository link to go to the associated GitHub repository, navigate to the package.json file and click on the Raw button to get the raw URL.
Then use Invoke-RestMethod with the raw URL to retrieve and parse the content of the package's package.json file into an object whose properties you can access (the for-display output below shows the properties in the left column, and their values to the right - note the dependencies / devDependencies properties denoting what other packages the package at hand depends on at runtime / design time):
PS> Invoke-RestMethod https://raw.githubusercontent.com/json5/json5/master/package.json
name : json5
version : 2.2.0
description : JSON for humans.
main : lib/index.js
module : dist/index.mjs
bin : lib/cli.js
browser : dist/index.js
types : lib/index.d.ts
files : {lib/, dist/}
engines : #{node=>=6}
scripts : #{build=rollup -c; build-package=node build/package.js; build-unicode=node build/unicode.js; coverage=tap --coverage-report html test; lint=eslint --fix .; prepublishOnly=npm run production; preversion=npm run production; production=npm run lint && npm test && npm run build; test=tap -Rspec --100 test; version=npm run build-package && git add package.json5}
repository : #{type=git; url=git+https://github.com/json5/json5.git}
keywords : {json, json5, es5, es2015…}
author : Aseem Kishore <aseem.kishore#gmail.com>
contributors : {Max Nanasy <max.nanasy#gmail.com>, Andrew Eisenberg <andrew#eisenberg.as>, Jordan Tucker <jordanbtucker#gmail.com>}
license : MIT
bugs : #{url=https://github.com/json5/json5/issues}
homepage : http://json5.org/
dependencies : #{minimist=^1.2.5}
devDependencies : #{core-js=^2.6.5; eslint=^5.15.3; eslint-config-standard=^12.0.0; eslint-plugin-import=^2.16.0; eslint-plugin-node=^8.0.1; eslint-plugin-promise=^4.0.1; eslint-plugin-standard=^4.0.0; regenerate=^1.4.0; rollup=^0.64.1; rollup-plugin-buble=^0.19.6; rollup-plugin-commonjs=^9.2.1; rollup-plugin-node-resolve=^3.4.0; rollup-plugin-terser=^1.0.1; sinon=^6.3.5; tap=^12.6.0; unicode-10.0.0=^0.7.5}
Deriving the URLs programmatically:
# Package name.
$npmPackageName = 'json5'
# Derive the package's npm registry URL
$npmUrl = "https://www.npmjs.com/package/$npmPackageName"
# Derive the associated API URL
$npmApiUrl = $npmUrl -replace '(?<=/)www(?=.)', 'replicate' -replace '/package'
# Derive the source-code repository URL
$repoUrl = Invoke-RestMethod $npmApiUrl |
ForEach-Object { $_.repository.url.Substring($_.repository.type.Length+1) }
# Assuming the source-code repository is a GitHub URL,
# derive the *raw* URL from it, from which files can be downloaded
# as-is.
$rawGitHubUrl= 'https://raw.githubusercontent.com/' + ($repoUrl -replace '\.git$' -replace '^https://github\.com/')
# Derive the raw URL for the package.json file.
$rawPackageJsonUrl = "$rawGitHubUrl/master/package.json"
# Parse the package.json file's JSON content into an object
$objectFromPackageJson = Invoke-RestMethod $rawPackageJsonUrl
# Output an example property.
$objectFromPackageJson.dependencies

Github Pages cannot find index.html only in some directories

Update: I got fed up and re-do everything from the ground-up and it fixes itself.
I have a github pages site built with Jekyll and Chirpy theme.
Locally, it runs great.
However when deployed on Github Pages there are a few directories that return the 404 page even though the path is valid and there is an index.html file in it.
Example:
https://catmandx.github.io/posts/Wgel-CTF-Writeup/ display normally
https://catmandx.github.io/tags/cmc/index.html returns 404
http://127.0.0.1:4000/tags/cmc/index.html display correcly.
I have temporarily make the repo public, it's here: https://github.com/catmandx/catmandx.github.io
I have been banging my head for a few hours now. I have tried committing and pushing again to re-run Actions, manually editing the /tags/cmc/index.html file in the gh-pages branch but nothing works.
This is the _config.yml file, not sure if it helps but here:
# The Site Settings
# v2.0
# https://github.com/cotes2020/jekyll-theme-chirpy
# © 2017-2019 Cotes Chung
# MIT licensed
# jekyll-seo-tag settings › https://github.com/jekyll/jekyll-seo-tag/blob/master/docs/usage.md
# --------------------------
title: Hoang Nguyen # the main title
tagline: Simple Blog. # it will display as the sub-title
description: >- # used by seo meta and the atom feed
A minimal, portfolio, sidebar,
bootstrap Jekyll theme with responsive web design
and focuses on text presentation.
# fill in the base hostname & protocol for your site, e.g., 'https://username.github.io'
url: 'https://catmandx.github.io'
author: Hoang Nguyen # change to your full name
avatar: /assets/img/avatar.jpg # support internet resources
github:
username: catmandx # change to your github username
#twitter:
# username: twitter_username # change to your twitter username
social:
name: Hoang Nguyen # it will shows as the copyright owner in Footer
email: hhoang.nov.13#gmail.com # change to your email address
links:
# The first element serves as the copyright owner's link
# - https://twitter.com/username # change to your twitter homepage
- https://github.com/catmandx # change to your github homepage
# Uncomment below to add more social links
- https://www.facebook.com/whohoi
# - https://www.linkedin.com/in/username
# google_site_verification: google_meta_tag_verification # change to your verification string
# --------------------------
# Only if your site type is GitHub Project sites and doesn't have a custom domain,
# change below value to '/projectname'.
baseurl: ''
# Change to your timezone › http://www.timezoneconverter.com/cgi-bin/findzone/findzone
timezone: Asia/Ho_Chi_Minh
google_analytics:
id: '' # Fill with your Google Analytics ID
pv:
# The Google Analytics pageviews switch.
# DO NOT enable it unless you know how to deploy the Google Analytics superProxy.
enabled: false
# the next options only valid when `google_analytics.pv` is enabled.
proxy_url: ''
proxy_endpoint: ''
cache: false # pv data local cache, good for the users from GFW area.
disqus:
comments: false # boolean type, the global switch for posts comments.
shortname: '' # Fill with your Disqus shortname. › https://help.disqus.com/en/articles/1717111-what-s-a-shortname
# Prefer color scheme setting.
#
# Note: Keep empty will follow the system prefer color by default,
# and there will be a toggle to switch the theme between dark and light
# on the bottom left of the sidebar.
#
# Available options:
#
# light - Use the light color scheme
#
# dark - Use the dark color scheme
#
theme_mode: # <light|dark>
# boolean type, the global switch for ToC in posts.
toc: true
paginate: 10
kramdown:
syntax_highlighter: rouge
syntax_highlighter_opts: # Rouge Options › https://github.com/jneen/rouge#full-options
css_class: highlight
# default_lang: console
span:
line_numbers: false
block:
line_numbers: true
start_line: 1
# DO NOT change this unless you're a Pro user on Jekyll and Web development,
# or you think you're smart enough to change other relevant URLs within this template.
permalink: /posts/:title/
collections:
tabs:
output: true
sort_by: order
defaults:
-
scope:
path: '' # An empty string here means all files in the project
type: posts
values:
layout: post
comments: true # Enable comments in posts.
toc: true # Display TOC column in posts.
breadcrumb:
-
label: Posts
url: /
-
scope:
path: _drafts
values:
comments: false
-
scope:
path: index.html
values:
breadcrumb:
-
label: Posts
-
scope:
path: tags
values:
breadcrumb:
-
label: Home
url: /
-
label: Tags
url: /tabs/tags/
-
scope:
path: categories
values:
breadcrumb:
-
label: Home
url: /
-
label: Categories
url: /tabs/categories/
-
scope:
path: ''
type: tabs # see `site.collections`
values:
layout: page
dynamic_title: true # Hide title in mobile screens.
breadcrumb:
-
label: Home
url: /
sass:
sass_dir: /assets/css
style: compressed
compress_html:
clippings: all
comments: all
endings: all
profile: false
blanklines: false
ignore:
envs: []
exclude:
- vendor
- Gemfile.lock
- Gemfile
- tools
- docs
- README.md
- LICENSE
- example
jekyll-archives:
enabled: [categories, tags]
layouts:
category: category
tag: tag
permalinks:
tag: /tags/:name/
category: /categories/:name/
Update: This is the log, as you can see, the files exists but all the subdirectories in /categories and /tags returns 404:
You can solve this issue by executing bash tools/init.sh
You will also have to run this init.sh every time there is a category/tag created.

automate uploading of glue script

We are currently using cloud formation to create a glue job (via codebuild and codepipeline). The one thing we are stuck on is how to automate the code that goes into the glue job.
Our current relevant piece of the cloudformation template looks like this:
MyJob:
Type: AWS::Glue::Job
Properties:
Command:
Name: glueetl
ScriptLocation: "s3://aws-glue-scripts//your-script-file.py"
DefaultArguments:
"--job-bookmark-option": "job-bookmark-enable"
ExecutionProperty:
MaxConcurrentRuns: 2
MaxRetries: 0
Name: cf-job1
Role: !Ref MyJobRole
The problem is is the "ScriptLocation". Looks like it is required to be an S3 location. How can we automate the upload of this. The code is in a .py file in our Git repository and I assume is uploaded to the artifact repository as are of the codebuild process, but how to access it?
Would like to hear how others are doing this. Thanks!
EDIT: I was able to find a similar stack overflow post:AWS Glue automatic job creation but it the answers really don't give a solution or understand the question posed.
I've written a tool to handle the upload of stack dependencies, including CloudFormation nested templates and non-inline Lambda functions.
Currently AWS Glue was not handled since I haven't try it in any project yet. But it should be easy to expand to support Glue.
The dependencies were defined in separate config file, and a piece of code within the tool is responsible for the config. Here's the sample config:
Nested CloudFormation templates:
# DEPENDS=( <ParameterName>=<NestedTemplate> )
#
# Required: Yes if has nested template, otherwise No
# Default: None
# Syntax:
# <ParameterName>: The name of template parameter that is referred at the
# value of nested template property `TemplateURL`.
# <NestedTemplate>: A local path or a S3 URL starting with `s3://` or
# `https://` pointing to the nested template.
# The nested templates at local is going to be uploaded
# to S3 Bucket automatically during the deployment.
# Description:
# Double quote the pairs which contain whitespaces or special characters.
# Use `#` to comment out.
# ---
# Example:
# DEPENDS=(
# NestedTemplateFooURL=/path/to/nested/foo/stack.json
# NestedTemplateBarURL=/path/to/nested/bar/stack.json
# )
Lambda functions:
# LAMBDA=( <S3BucketParameterName>:<S3KeyParameterName>=<LambdaFunction> )
#
# Required: Yes if has None-inline Lambda Function, otherwise No
# Default: None
# Syntax:
# <S3BucketParameterName>: The name of template parameter that is referred
# at the value of Lambda property `Code.S3Bucket`.
# <S3KeyParameterName>: The name of template parameter that is referred
# at the value of Lambda property `Code.S3Key`.
# <LambdaFunction>: A local path or a S3 URL starting with `s3://` pointing
# to the Lambda Function.
# The Lambda Functions at local is going to be zipped and
# uploaded to S3 Bucket automatically during the deployment.
# Description:
# Double quote the pairs which contain whitespaces or special characters.
# Use `#` to comment out.
# ---
# Example:
# DEPENDS=(
# S3BucketForLambdaFoo:S3KeyForLambdaFoo=/path/to/LambdaFoo.py
# S3BucketForLambdaBar:S3KeyForLambdaBar=s3://mybucket/LambdaBar.py
# )
The tools were written in bash and come with 2 parts:
xsh: It works as a bash library framework.
xsh-lib/aws: It's a library of xsh.
The code you may need to expand is located in xsh-lib/aws/functions/cfn/deploy.sh.
The example deploy command looks like:
$ xsh aws/cfn/deploy -C /path/to/your/template-and-config-dir -t stack.json -c sample.conf
I'm considering to abstract the dependencies such as CloudFormation template, Lambda functions and Glue, into a single interface for both configs and handlers.
This will make it easier to add new dependency handlers to the deployer.

How to clear the OPcache on a BasicAuth protected environment with typo3/surf?

On a TYPO3 project I'm working the Production/Staging (or Production/Dev, or any other) environment is protected by HTTP BasicAuth (basic access authentication).
The instance get's deployed via typo3/surf.
At some point typo3/surf must create a temporary php file, which can be accessed
later: after the switch was done and the new deployment is reachable via the frontend.
How can I configure typo3/surf to access the previously generated OPcache clearing script via the frontend on a BasicAuth protected environment?
Configuring typo3/surf to reset the PHP OPcache1
Four steps are basically necessary to configure the OPcache clearing/reset script:
Set task options for \TYPO3\Surf\Task\Php\WebOpcacheResetCreateScriptTask
Add task \TYPO3\Surf\Task\Php\WebOpcacheResetCreateScriptTask the an early stage (e.g. package but definitely before transfer)
Set task options for \TYPO3\Surf\Task\Php\WebOpcacheResetExecuteTask
Add task \TYPO3\Surf\Task\Php\WebOpcacheResetExecuteTask after stage switch
Here are the necessary snippets for your onInitialize function2 within your deployment configuration script:
Set task options for the "Create Script Task":
Since the "Respect WebDirectory" patch, the path to the script must not to be configured manually as it automatically uses the right WebDirectory path (which is set via options beforhand).
If you are using an older typo3/surf version or you have any special requirement you can set option scriptBasePath to set the absolute path to the resulting file:
# In this example, I have to set the absolute path for the resulting php file.
# Since the deployment run in GitLab CI I get the path to the root of the project's GIT
# repository via the environment variable `CI_PROJECT_DIR`. Since the path to the webDirectory
# inside the GIT repository is `<GitRepoRootFOlder>/app/web` I add it manually and concatenate
# it as final string for the option `scriptBasePath`:
$workflow->setTaskOptions(\TYPO3\Surf\Task\Php\WebOpcacheResetCreateScriptTask::class, [
'scriptBasePath' => \TYPO3\Flow\Utility\Files::concatenatePaths([getenv('CI_PROJECT_DIR'), '/app/web']),
]);
Set task options for the "Execute Task":
At this point, we provide username and password
$workflow->setTaskOptions('TYPO3\\Surf\\Task\\Php\\WebOpcacheResetExecuteTask', [
'baseUrl' => $application->getOption('baseUrl'),
'stream_context' => [
'http' => [
'header' => 'Authorization: Basic '.base64_encode("username:password"),
],
],
]);
Activate both Tasks:
$workflow->beforeStage('transfer', \TYPO3\Surf\Task\Php\WebOpcacheResetCreateScriptTask::class, $application)
->afterStage('switch', \TYPO3\Surf\Task\Php\WebOpcacheResetExecuteTask::class, $application);
This answer shows only the necessary parts for the OPcache reset process!
Please check also the TYPO3 CMS deployment configuration example in the official documentation.
Footnotes
1 This answer is based on typo3/surf GIT branch dev-master, version 2.x
2 Example where to place the mentioned snippets:
$deployment->onInitialize(function () use ($deployment, $application) {
/** #var SimpleWorkflow $workflow */
$workflow = $deployment->getWorkflow();
# the mentioned snippets have to be placed next to your existing configuration
});