How to create and correctly assign projects to filter tool in Hugo using blogdown? - project

I'm quite new to blogdown and Hugo. I'm trying to create a project section to the Academic theme on my own. I successfully create the section and the correct toolbar-filter:
---
widget: portfolio
headless: true
weight: 65
title: Research Projects
content:
page_type: projects
# Default filter index (e.g. 0 corresponds to the first `filter_button` instance below).
filter_default: 0
filter_button:
- name: Joint Research Center
tag: jrc
- name: Abilities & Intergenerational Mobility
tag: aim
- name: Future research
design:
columns: '2'
view: List
---
Then, in the content folder I have projects with 3 different folders containing the corresponding .md file content. Like
blogdown/content/projects/
├── jrc
│ └── jrc_index.md
└── aim
│ └── aim_index.md
│
└── Future
└── future_index.md
And the jrc_index.md looks like:
---
title: Joint Research Center
external_link: ""
summary: ""
tags:
- aim
url_code: ""
url_pdf: ""
url_slides: ""
url_video: ""
---
Some content and code
This will be correctly displayed under the first filter tool option. However, the other two internal projects are not displayed. How can I assign each internal project/page to the corresponding filter-tool?
Moreover, I do not specify any date in the .md file, but when serving the site the internal project shows the default Jan 1, 0001

Related

Reuse parent symbols in child module

I am seeking to re-use the same role/class names in a child module as in its parent. You know, like a specialization.
The aim is to be able to re-use the same script code for both the parent and child Series variants by simply changing use Dan to use Dan::Pandas at the top.
I am trying to stick to role rather than class compostion where I can so that the behaviours can be applied to other objects with eg. class GasBill does Series;
Here is the MRE:
me#ubuntu:~/spike# tree
.
├── lib
│   ├── Dan
│   │   └── Pandas.rakumod
│   └── Dan.rakumod
└── spike.raku
Dan.rakumod:
1 unit module Dan;
2
3 role Series is export {
4 method no { "no" }
5 }
Pandas.rakumod:
1 unit module Dan::Pandas;
2
3 use Dan;
4
5 role Series does Dan::Series is export {
6 method yo { "yo" }
7 }
spike.raku:
1 use lib './lib';
2 use Dan::Pandas;
3
4 my $s = Series.new; #version 1
5 #my $s = Dan::Pandas::Series.new; #version 2 "fqm"
6
7 say $s.no, $s.yo, $s.^name;
My version 1 says:
No appropriate parametric role variant available for 'Dan::Series':
Ambiguous call to '(Dan::Series)'; these signatures all match:
(::$?CLASS ::::?CLASS Mu $)
(::$?CLASS ::::?CLASS Mu $)
in block <unit> at spike.raku line 4
My version 2 says:
Could not find symbol '&Series' in 'Dan::Pandas'
in block <unit> at spike.raku line 5
I am trusting that raku does have a way to do this, but darned if I can work it out!
TL;DR You need a solution that avoids having two roles with the same full name.
Golf
role R {}
role R {}
R.new
displays:
No appropriate parametric role variant available for 'R':
Ambiguous call to '(R)'; these signatures all match:
(::$?CLASS ::::?CLASS Mu $)
(::$?CLASS ::::?CLASS Mu $)
(See Gut-referencing warning when composing stubbed role for a bit more discussion of the error message.)
A solution
Just Dan.
Dan.rakumod:
unit module Dan;
role Series is export { method no { "no" } }
spike.raku:
use lib '.';
use Dan;
my $s = Series.new;
.say for $s.?no, $s.?yo, $s.^name;
Running spike displays:
no
Nil
Dan::Series
Introduce Dan::Pandas.
Alter Dan so variant modules can use it without them importing Dan's unqualified Series symbol into their lexical scopes.
(Because otherwise Dan's unqualified Series symbol ends up being in their lexical scopes as well as their own unqualified Series symbol, and you get the "Ambiguous call" error.)
Dan:
unit module Dan;
role Series is export { method no { "no" } }
class Dan::Variant-Export-Dummy-Type is export(:Variant-Exports) {}
The change is the last line, a dummy declaration with a new export tag. (Introducing the new tag some cleaner way is left as an exercise for readers.)
Dan::Pandas:
unit module Dan::Pandas;
use Dan :Variant-Exports;
role Series does Dan::Series is export { method yo { "yo" } }
The change is using the new :Variant-Exports tag with the use Dan ... statement. This stops Dan's Series role being imported under that unqualified name into Dan::Pandas.
User programs will now work as expected/wanted.
Just change the use statement in spike.raku:
use lib '.';
use Dan::Pandas;
my $s = Series.new;
.say for $s.?no, $s.?yo, $s.^name;
Running with just this change for user programs:
no
yo
Dan::Pandas::Series
Note how there's no need for programs using using these modules to know about the :Variant-Exports tag. That's just an internal detail of the Dan module and the Dan::Pandas etc modules that lets them avoid the unintended role variant duplication problem shown at the start of this answer.
If I'm understanding correctly, you don't need/want to use the non-specialized role in the final module (that is, you aren't using the Series defined in Dan.rakumod in spike.raku – you're only using the specialized Series defined in Pandas.rakumod). Is that correct?
If so, the solution is simple: just don't export the Series from Dan.rakumod – it's still our scoped (the default for roles) so you can still use it in Pandas.rakumod exactly the way you currently do (Dan::Series). But, since it's not exported, you it won't create a name clash with the non-prefixed Series.
My Solution
Taking the advice of #codesections [that FQMs can be used without is export] and #raiph [that you can qualify the export with e.g. is export(:ALL)], then - yes - there is a neat way to do this.
viz. https://docs.raku.org/language/modules#Exporting_and_selective_importing
Turns out that this is low touch (just change two lines) and, as I originally hoped, something that raku designers have anticipated.
Here is the code from my OP adjusted...
Dan.rakumod:
1 unit module Dan;
2
3 role Series is export(:ALL) { #<== added the selective export
4 method no { "no" }
5 }
Pandas.rakumod (no change):
1 unit module Dan::Pandas;
2
3 use Dan;
4
5 role Series does Dan::Series is export {
6 method yo { "yo" }
7 }
spike.raku:
1 use lib './lib';
2 #use Dan::Pandas; #\ either of these work
3 use Dan :ALL; #/ <== use :ALL to get 'Series'
4
5 my $s = Series.new;
6
7 say $s.no, $s.yo, $s.^name; #No such method 'yo' if Pandas not used

Terraform, how to call 100 times module with seperate values

I have a problem with terraform configuration which I really don't know how to resolve. I have written module for policy assigments, module as parameters taking object with 5 attributes. The question is if it is possible to split into folder structure tfvars file. I mean eg.
I have main folder subscriptions -> folder_subscription_name -> some number of files tfvars with configuration for each of the policy assigment
Example of each of the file
testmap = {
var1 = "test1"
var2 = "test2"
var3 = "test3"
var4 = "test4"
var5 = "test5"
}
In the module I would like to iterate over all of the maps combine into list of maps. Is it good approach? How to achive that or maybe I should use something other to do it like terragrunt ?
Please give me some tips what is the best way to achive that, basically the goal is that I don't want to have one insanely big tvars file with list of 100 maps but splitted into 100 configuration file for each of the assignment.
Based on the comment on the original question:
The question is preety simple how to keep input variables for each of
resource in seperate file instead of keeping all of them in one very
big file
I would say you aim at having different .tfvars files. For example, you could have a dev.tfvars and a prod.tfvars file.
To plan your deployment, you can pass those file with:
terraform plan --var-file=dev.tfvars -out planoutput
To apply those changes
terraform apply planoutput

Moodle set module sequence grammatically

after managing to add modules to Moodle programmaticaly (see my old question here) I now also need to add the module at a specific place.
Lets take for example a sample course in Moodle, I have:
Section 0
- Module 1
- --> ADD NEW MODULE HERE <--
- Module 2
Section 1
- Module 1
- Module 2
Section 2
So I need to add the new module I create programatically inbetween module 1 and 2 of section 0.
I know that the order of modules come from table mdl_course_sections and its specified in the column sequence where the ids of the modules exist in comma separated values
Is there a function in Moodle that does that? Set the sequence of a section? I don't want to mess with the DB directly.
After I got some help from Moodle community (thanks Sam Chaffee) here is the solution
//...Do stuff to create module object...
// ...
$moduleinfo = add_moduleinfo($newlabel, $section);
//lets get all sections and modules of the course
$coursemodinfo = get_fast_modinfo($course->id, 0, false);
//get all sections of the course
$coursesections = $coursemodinfo->get_sections();
//get the first section, get_section will return an array of sections so I get position 0 to get section 1
$section01 = $coursesections[0];
//get the first module in the section so we can add on top of it
$firstmodid = $section01[0];
//We need to get cm_info for the specific mod
$mod = $coursemodinfo->get_cm($moduleinfo->coursemodule);
//we also need section_info for the section we want to move to
$sectioninfo = $coursemodinfo->get_section_info(0);
//move the newly created module to section 01 but before $firstmodid
moveto_module($mod, $sectioninfo, $firstmodid);

Find the tfs path of merged branch

Using TFS, I have trunk $/project/trunk and a branch $/project/dev/feature/new_one.
I have merged my branch back to trunk as follows:
C33($/project/trunk)
| \
| \
| C32($/project/dev/feature/new_one)
| |
| |
| |
...
I use the TFS API and can find the merge changeset C33. With the method QueryMerges(), I'm able to find the parent changeset C32 with all the changes on the files, but not the information I need :(
Is there a way, using the TFS API, to find the repository path of the branch merged $/project/dev/feature/new_one?
With the changeset C32, I'm only able to get paths of modified files, like $/project/dev/feature/new_one/path/to/file.txt but I'm unable to extract the path of the branch from the full path of the file :(
PS : A solution working since TFS2008 will be the best, but if it works only since 2010, it should be good...
PS2 : solving this problem will help to manage merge changesets in git-tfs which I develop...
Unfortunately there is no API method to get a branch for a given item path, which you would think is a fairly common use case.
TFS 2010 onwards you can use VersionControlServer.QueryRootBranchObjects to query all branches in version control. Using RecursionType.Full as the parameter to this method you will get a BranchObject array of all branches with no parent and all of their descendents. You can then determine a branch for a given file path as follows:
var collection = new TfsTeamProjectCollection(new Uri("http://tfsuri"));
var versionControl = collection.GetService<VersionControlServer>();
var branchObjects = versionControl.QueryRootBranchObjects(RecursionType.Full);
var mergeFilePath = "$/project/dev/feature/new_one/path/to/file.txt";
var branch = branchObjects.SingleOrDefault(b => {
var branchPath = b.Properties.RootItem.Item;
return mergeFilePath.StartsWith(branchPath.EndsWith("/") ? branchPath : branchPath + "/");
});
Console.WriteLine(branch.Properties.RootItem.Item);
As shown, the path to the branch is at BranchObject.Properties.RootItem.Item. I believe it is safe to find the relevant BranchObject in the array simply by checking which branch's path is contained in the merge file's path (given it is only possible match at most one branch as TFS enforces that only one branch can exist in a given folder hierarchy).
Just to be aware, I have been burned by this Connect issue when using QueryRootBranchObjects in TFS 2012. The cause were some spurious branches that had apostrophes in the branch name.
The workaround to this is to use VersionControlServer.QueryBranchObjects, however this takes an item identifier which is the exact path to the branch. Clearly you don't know the branch path at this point as all you have is a file path, so you have to recurse up the directories of the file path calling QueryBranchObjects each time until you get a match.

Import xx.sql file to execute by using Ebean

Is there any way to execute SQLs directly read from SQL files(xx.sql) in Ebean?
For example, if I had a SQL file including several SQL statements (values already written in the file), is there any way to execute this SQL file by using Ebean?
You have at least two options out of the box:
Play evolutions are meant to updating DB schema, so you can use them also for inserting initial data (if they are flat, and will not contain relations to the objects not created yet), sample evolution for MySQL:
# --- !Ups
INSERT INTO your_table (some_field) VALUES ('New value');
# --- !Downs
DELETE FROM your_table WHERE some_field = 'New value`;
Use Global object and insert initial data using common Ebean's way:
public void onStart(Application app) {
if (YourModel.find.findRowCount() == 0) {
YourModel newItem = new YourModel();
newItem.someField = "New value";
newItem.save();
YourModel newItem2 = new YourModel();
// etc....
}
}
For the second approach you can check the way how to read YAML file holding initial data with Global object of Zentask sample (the file with sample is placed in conf directory)
Edit:
Take a closer look to the initial-data.yml, there are also relations between tasks and projects, so they have fixed id values. So you need do the same in your yaml:
projects:
- !!models.Project
id: 1
name: Play 2.0
folder: Play framework
tasks:
- !!models.Task
title: Fix the documentation
done: false
folder: Todo
project: !!models.Project
id: 1